piper.verbs.order_by

piper.verbs.order_by(df: pandas.core.frame.DataFrame, *args, **kwargs)pandas.core.frame.DataFrame[source]

order/sequence dataframe

This is a wrapper function rather than using e.g. df.sort_values() For details of args, kwargs - see help(pd.DataFrame.sort_values)

Note

The first argument and/or keyword ‘by’ is checked to see:

  • For each specified column value If it starts with a minus sign, assume ascending=False

Examples

%%piper

sample_data()
>> group_by(['countries', 'regions'])
>> summarise(totalval1=('values_1', 'sum'))
>> group_calc(index='countries')
>> order_by(['countries', '-group%'])
>> head(8)

|                      |   totalval1 |   group% |
|:---------------------|------------:|---------:|
| ('France', 'West')   |        4861 |    42.55 |
| ('France', 'North')  |        2275 |    19.91 |
| ('France', 'East')   |        2170 |    19    |
| ('France', 'South')  |        2118 |    18.54 |
| ('Germany', 'North') |        2239 |    30.54 |
| ('Germany', 'East')  |        1764 |    24.06 |
| ('Germany', 'South') |        1753 |    23.91 |
| ('Germany', 'West')  |        1575 |    21.48 |
Parameters
  • df – dataframe

  • *args – arguments for wrapped function

  • **kwargs – keyword-parameters for wrapped function

Returns

Return type

A pandas DataFrame