0

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
Carola
  • 366
  • 4
  • 18

1 Answers1

1

Try this:

df.groupby('ID').count()
gtomer
  • 5,643
  • 1
  • 10
  • 21