I have the following data frame that has been obtained by applying df.groupby(['category', 'unit_quantity']).count()
category | unit_quantity | Count |
---|---|---|
banana | 1EA | 5 |
eggs | 100G | 22 |
100ML | 1 | |
full cream milk | 100G | 5 |
100ML | 1 | |
1L | 38 |
Let's call this latter dataframe as grouped
. I want to find a way to regroup using columns unit_quantity
and Count
it and get
category | unit_quantity | Count | Most Frequent unit_quantity |
---|---|---|---|
banana | 1EA | 5 | 1EA |
eggs | 100G | 22 | 100G |
100ML | 1 | 100G | |
full cream milk | 100G | 5 | 1L |
100ML | 1 | 1L | |
1L | 38 | 1L |
Now, I tried to apply grouped.groupby(level=1).max()
which gives me
unit_quantity | |
---|---|
100G | 22 |
100ML | 1 |
1EA | 5 |
1L | 38 |
Now, because the indices of the latter and grouped
do not coincide, I cannot join it using .merge
. Does someone know how to solve this issue?
Thanks in advance