Back
I am trying to count all the instances of all values of col_a
for example:
col_a A B C A D B A
col_a
A
B
C
D
Is there one line of code I can use that would tell me how many times each value (A,B,C,D) exist in that column?
So, the solution for this can be value_counts
df.col_a.value_counts()
Or, you can use groupby with size:
>>> df.groupby('col_a').size()col_aA 3B 2C 1D 1dtype: int64>>>
>>> df.groupby('col_a').size()
A 3
B 2
C 1
D 1
dtype: int64
>>>
31k questions
32.8k answers
501 comments
693 users