Count the number of occurrences from a column

Viewed 27

Be a DataFrame in pandas of this format:

ID time other
0 81219 blue
0 32323 green
1 423 red
1 4232 blue
1 42424 red
2 42422 blue

I simply want to create a DataFrame like the following by counting the number of times each row is output in the previous DataFrame.

ID number_appears
0 2
1 3
2 1
1 Answers

Try this:

df.groupby('ID').count()
Related