sort_values

sort_values#

NestedFrame.sort_values(by, *, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None)[source]#

Sort by the values along either axis.

Parameters:
  • by (str or list of str) –

    Name or list of names to sort by.

    Access nested columns using nested_df.nested_col (where nested_df refers to a particular nested dataframe and nested_col is a column of that nested dataframe).

  • axis ({0 or 'index', 1 or 'columns'}, default 0) – Axis to be sorted.

  • ascending (bool or list of bool, default True) – Sort ascending vs. descending. Specify list for multiple sort orders. If this is a list of bools, must match the length of the by.

  • inplace (bool, default False) – If True, perform operation in-place.

  • kind ({'quicksort', 'mergesort', 'heapsort'}, default 'quicksort') – Choice of sorting algorithm. See also ndarray.np.sort for more information. mergesort is the only stable algorithm. For DataFrames, this option is only applied when sorting on a single column or label.

  • na_position ({'first', 'last'}, default 'last') – Puts NaNs at the beginning if first; last puts NaNs at the end.

  • ignore_index (bool, default False) – If True, the resulting axis will be labeled 0, 1, …, n - 1. Always False when applied to nested layers.

  • key (callable, optional) – Apply the key function to the values before sorting.

Returns:

DataFrame with sorted values if inplace=False, None otherwise.

Return type:

DataFrame or None

Examples

>>> from nested_pandas.datasets.generation import generate_data
>>> nf = generate_data(5,5, seed=1)
>>> # Sort nested values
>>> nf.sort_values(by="nested.band")
          a         b                                             nested
0  0.417022  0.184677  [{t: 13.40935, flux: 98.886109, flux_error: 1....
1  0.720324  0.372520  [{t: 13.70439, flux: 68.650093, flux_error: 1....
2  0.000114  0.691121  [{t: 4.089045, flux: 83.462567, flux_error: 1....
3  0.302333  0.793535  [{t: 17.562349, flux: 1.828828, flux_error: 1....
4  0.146756  1.077633  [{t: 0.547752, flux: 75.014431, flux_error: 1....