I have a dataframe of the following shape:
import pandas as pd
l = []
l.append({"t":'a', 'w': 'x'})
l.append({"t":'a', 'w': 'x'})
l.append({"t":'a', 'w': 'y'})
l.append({"t":'b', 'w': 'y'})
l.append({"t":'b', 'w': 'y'})
l.append({"t":'b', 'w': 'z'})
l.append({"t":'b', 'w': 'y'})
df = pd.DataFrame(l)
I want to first aggregate based on t colmun and then expand to show each items frequency in w column. In other words I want the following result:
t w freq
0 a x 2
1 a y 1
2 b y 3
3 b z 1
How is this possible? I tried so many different ways with no result.