I have following dataframe in pandas
date prod hourly_bucket tank trans flag
01-01-2019 TP 05:00:00-06:00:00 2 Preset Peak
01-01-2019 TP 05:00:00-06:00:00 2 Preset Peak
01-01-2019 TP 05:00:00-06:00:00 2 Non Preset Peak
02-01-2019 TP 05:00:00-06:00:00 2 Preset Lean
02-01-2019 TP 05:00:00-06:00:00 2 Preset Lean
02-01-2019 TP 05:00:00-06:00:00 2 Non Preset Lean
My Desired dataframe would be aggregation at day level and tank level and then taking a count of how many Preset,Non-Preset transactions in Lean and Peak hours
date tank Lean_Non_Preset Lean_Preset Peak_Non_Preset Peak_Preset
01-01-2019 2 1 2 1 2
I am doing following in pandas
lean_peak_preset_cnt = df.pivot_table(index=['date','tank'], columns=['flag'],values=['trans'],aggfunc='count').reset_index()
But it does not give me the required solution