Given the following dataframe:
df = pd.DataFrame({
'B': ['a', 'a', 'c', 'd', 'a'],
'C': ['aa', 'bb', '', 'dd', 'do'],
})
B C
0 a aa
1 a bb
2 c cb
3 d dd
4 a do
value_counts method counts the occurrences of all values in column ‘B
‘:
df.B.value_counts()
a 3
d 1
c 1
solved Count unique strings by column in pandas DataFrame [closed]