1

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

for ex.

col_a
 A
 B
 C
 A
 D
 B
 A

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?

U13-Forward
  • 69,221
  • 14
  • 89
  • 114
Chris90
  • 1,868
  • 5
  • 20
  • 42

2 Answers2

1

So the solution will be value_counts

df.col_a.value_counts()
BENY
  • 317,841
  • 20
  • 164
  • 234
1

Or use groupby with size:

>>> df.groupby('col_a').size()
col_a
A    3
B    2
C    1
D    1
dtype: int64
>>> 
U13-Forward
  • 69,221
  • 14
  • 89
  • 114