I have a pandas DataFrame with 3 columns : product
, region
, and cost
.
I want to display a pivot table using pivottable.js in a Jupyter notebook such that product
are rows, region
are columns and cost
are values.
I have tried :
from pivottablejs import pivot_ui
import pandas as pd
df = pd.DataFrame({'region':['N', 'S', 'W', 'E', 'N', 'S', 'W', 'E'],
'product':['P1', 'P1', 'P1', 'P1', 'P2', 'P2', 'P2', 'P2'],
'cost':[10, 13, 17, 28, 29, 23, 17, 18]})
pivot_ui(df, rows=['product'], cols=['region'], values=['cost'])
But this does not work, since there does not exist a values
attribute for pivot_ui()
.
How to do that ?