def sort_values(self, inplace=False, ascending=True, na_position='<STR_LIT>'):
inplace = validate_bool_kwarg(inplace, '<STR_LIT>')<EOL>if na_position not in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>msg = '<STR_LIT>'<EOL>raise ValueError(msg.format(na_position=na_position))<EOL><DEDENT>sorted_idx = nargsort(self,<EOL>ascending=ascending,<EOL>na_position=na_position)<EOL>if inplace:<EOL><INDENT>self._codes = self._codes[sorted_idx]<EOL><DEDENT>else:<EOL><INDENT>return self._constructor(values=self._codes[sorted_idx],<EOL>dtype=self.dtype,<EOL>fastpath=True)<EOL><DEDENT>
Sort the Categorical by category value returning a new
Categorical by default.

While an ordering is applied to the category values, sorting in this
context refers more to organizing and grouping together based on
matching category values. Thus, this function can be called on an
unordered Categorical instance unlike the functions 'Categorical.min'
and 'Categorical.max'.

Parameters
----------
inplace : bool, default False
    Do operation in place.
ascending : bool, default True
    Order ascending. Passing False orders descending. The
    ordering parameter provides the method by which the
    category values are organized.
na_position : {'first', 'last'} (optional, default='last')
    'first' puts NaNs at the beginning
    'last' puts NaNs at the end

Returns
-------
Categorical or None

See Also
--------
Categorical.sort
Series.sort_values

Examples
--------
>>> c = pd.Categorical([1, 2, 2, 1, 5])
>>> c
[1, 2, 2, 1, 5]
Categories (3, int64): [1, 2, 5]
>>> c.sort_values()
[1, 1, 2, 2, 5]
Categories (3, int64): [1, 2, 5]
>>> c.sort_values(ascending=False)
[5, 2, 2, 1, 1]
Categories (3, int64): [1, 2, 5]

Inplace sorting can be done as well:

>>> c.sort_values(inplace=True)
>>> c
[1, 1, 2, 2, 5]
Categories (3, int64): [1, 2, 5]
>>>
>>> c = pd.Categorical([1, 2, 2, 1, 5])

'sort_values' behaviour with NaNs. Note that 'na_position'
is independent of the 'ascending' parameter:

>>> c = pd.Categorical([np.nan, 2, 2, np.nan, 5])
>>> c
[NaN, 2.0, 2.0, NaN, 5.0]
Categories (2, int64): [2, 5]
>>> c.sort_values()
[2.0, 2.0, 5.0, NaN, NaN]
Categories (2, int64): [2, 5]
>>> c.sort_values(ascending=False)
[5.0, 2.0, 2.0, NaN, NaN]
Categories (2, int64): [2, 5]
>>> c.sort_values(na_position='first')
[NaN, NaN, 2.0, 2.0, 5.0]
Categories (2, int64): [2, 5]
>>> c.sort_values(ascending=False, na_position='first')
[NaN, NaN, 5.0, 2.0, 2.0]
Categories (2, int64): [2, 5]