Pandas: Split arrays and count [duplicate]
Solution 1:
Given this DataFrame:
df = pd.DataFrame({'col':[['Action', 'Adventure', 'Science Fiction', 'Thriller'], ['Action', 'Crime', 'Thriller']]})
You can explode
the column and use value_counts
:
out = df['col'].explode().value_counts()
Output:
Action 2
Adventure 1
Crime 1
Science Fiction 1
Thriller 2
dtype: int64