I need to get the frequency of each element in lists when the list is in a pandas dataframe columns.
it like data.groupby(["element in a","element in b"]).size(),but column 'a' and column 'b' is list.
I need the size of each combination by element in 'a' and b'b'
in data:
a b
0 [17, 21, 22] [zhinan, shejiyuanze, fankui]
1 [17, 21, 23] [zhinan, shejiyuanze]
2 [17, 21] [zhinan, shejiyuanze, fankui]
3 [17, 21, 22] [zhinan, shejiyuanze, fankui]
4 [17, 21] [zhinan, shejiyuanze, yizhi]
Desired Output:
17 21 22 23
zhinan 5 5 2 1
shejiyuanze . . . .
fankui . . . .
yizhi . . . .
For example, when a=17 and b=zhinan, the number is 5.when a=17 and b=fankui,the number is 3.when a=23 and b= fankui or b=yizhi the number is 0.
I was wondering if there is a efficient/direct way to do this.
thanks
pd.data.pivot(index='b', columns='a')but I fail to see how u are counting frequencies here? could you elaborate I lack the information to reproduce ur example