plydata.helper_verbs.arrange_all¶
-
class
plydata.helper_verbs.
arrange_all
(*args, **kwargs)[source]¶ Arrange by all columns
- Parameters
- data
dataframe
, optional Useful when not using the
>>
operator.- functions
callable()
ortuple
ordict
orstr
Functions to alter the columns before they are sorted:
function (any callable) - Function is applied to the column and the result columns replace the original columns.
tuple
of functions - Each function is applied to all of the columns and the name (__name__
) of the function is postfixed to resulting column names.dict
of the form{'name': function}
- Allows you to apply one or more functions and also control the postfix to the name.str
- String can be used for more complex statements, but the resulting names will be terrible.
Note that, the functions do not change the data, they only affect the sorting.
- args
tuple
Arguments to the functions. The arguments are pass to all functions.
- kwargs
dict
Keyword arguments to the functions. The keyword arguments are passed to all functions.
- data
Notes
Do not use functions that change the order of the values in the array. Such functions are most likely the wrong candidates, they corrupt the data. Use function(s) that return values that can be sorted.
Examples
>>> import pandas as pd >>> import numpy as np >>> from plydata import * >>> df = pd.DataFrame({ ... 'alpha': list('aaabbb'), ... 'beta': list('babruq'), ... 'theta': list('cdecde'), ... 'x': [1, 2, 3, 4, 5, 6], ... 'y': [6, 5, 4, 3, 2, 1], ... 'z': [7, 9, 11, 8, 10, 12] ... })
Arranging in ascending order.
>>> df >> arrange_all() alpha beta theta x y z 1 a a d 2 5 9 0 a b c 1 6 7 2 a b e 3 4 11 5 b q e 6 1 12 3 b r c 4 3 8 4 b u d 5 2 10
Arranging in descending order.
>>> df >> arrange_all(pd.Series.rank, ascending=False) alpha beta theta x y z 4 b u d 5 2 10 3 b r c 4 3 8 5 b q e 6 1 12 2 a b e 3 4 11 0 a b c 1 6 7 1 a a d 2 5 9