0 votes
1 view
in Python by (17.8k points)

I am trying to count all the instances of all values of col_a

for example:









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?

1 Answer

0 votes
by (16.8k points)

So, the solution for this can be value_counts


Or, you can use groupby with size:

>>> df.groupby('col_a').size()


A    3

B    2

C    1

D    1

dtype: int64


Welcome to Intellipaat Community. Get your technical queries answered by top developers !