piper.verbs.pivot_table

piper.verbs.pivot_table(df: pandas.core.frame.DataFrame, *args, freq: str = 'M', format_date: bool = False, **kwargs)pandas.core.frame.DataFrame[source]

create Excel like pivot table

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

Examples

from piper.verbs import pivot_wider
from piper.factory import sample_data
import piper.defaults

df = sample_data()

index=['dates', 'order_dates', 'regions', 'ids']
pvt = pivot_wider(df, index=index, freq='Q', format_date=True)
pvt.head()

|                                       |   values_1 |   values_2 |
|:--------------------------------------|-----------:|-----------:|
| ('Mar 2020', 'Mar 2020', 'East', 'A') |    227.875 |     184.25 |
| ('Mar 2020', 'Mar 2020', 'East', 'B') |    203.2   |     168    |
| ('Mar 2020', 'Mar 2020', 'East', 'C') |    126     |     367    |
| ('Mar 2020', 'Mar 2020', 'East', 'D') |    125.667 |     259    |
| ('Mar 2020', 'Mar 2020', 'East', 'E') |    194     |     219    |
Parameters
  • df – dataframe

  • *args – arguments for wrapped function

  • **kwargs – keyword-parameters for wrapped function

Returns

Return type

pandas DataFrame object