piper.verbs.group_by¶
-
piper.verbs.group_by(df: pandas.core.frame.DataFrame, *args, freq: str = 'D', **kwargs) → pandas.core.frame.DataFrame.groupby[source]¶ Group by dataframe
This is a wrapper function rather than using e.g. df.groupby() For details of args, kwargs - see help(pd.DataFrame.groupby)
The first argument or by keyword are checked in turn and converted to pd.Grouper objects. If any group fields are ‘date’ like, they can be represented as various ‘frequencies’ types.
See https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases for list of valid frequency strings.
Examples
%%piper sample_data() >> where("ids == 'A'") >> where("values_1 > 300 & countries.isin(['Italy', 'Spain'])") >> group_by(['countries', 'regions']) >> summarise(total_values_1=pd.NamedAgg('values_1', 'sum'))
- Parameters
df – dataframe
*args – arguments for wrapped function
freq – Default ‘d’ (days)
**kwargs – keyword-parameters for wrapped function
- Returns
- Return type
pandas DataFrame object