bigframes.pandas.Series.sort_index#

Series.sort_index(*, axis=0, inplace: Literal[False] = False, ascending=True, na_position='last') Series[source]#
Series.sort_index(*, axis=0, inplace: Literal[True] = False, ascending=True, na_position='last') None

Sort Series by index labels.

Returns a new Series sorted by label if inplace argument is False, otherwise updates the original series and returns None.

Examples:

>>> s = bpd.Series(['a', 'b', 'c', 'd'], index=[3, 2, 1, 4])
>>> s.sort_index()
1    c
2    b
3    a
4    d
dtype: string

Sort Descending

>>> s.sort_index(ascending=False)
4    d
3    a
2    b
1    c
dtype: string

By default NaNs are put at the end, but use na_position to place them at the beginning

>>> s = bpd.Series(['a', 'b', 'c', 'd'], index=[3, 2, 1, np.nan])
>>> s.sort_index(na_position='first')
<NA>    d
1.0     c
2.0     b
3.0     a
dtype: string
Parameters:
  • axis ({0 or 'index'}) – Unused. Parameter needed for compatibility with DataFrame.

  • inplace (bool, default False) – Whether to modify the Series rather than creating a new one.

  • ascending (bool or list-like of bools, default True) – Sort ascending vs. descending. When the index is a MultiIndex the sort direction can be controlled for each level individually.

  • na_position ({'first', 'last'}, default 'last') – If ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end. Not implemented for MultiIndex.

Returns:

The original Series sorted by the labels or None if inplace=True.

Return type:

bigframes.pandas.Series or None