0

I need to count the times that two values are repeated in the dataframe and create a column that has that count:

I have this example dataframe:

date cod type
20210127 29 h
20210127 29 h
20210126 26 h
20210125 26 h

I need this:

date cod type count
20210127 29 h 2
20210126 26 h 1
20210125 26 h 1

I try this like that :

df['count'] = df.apply(lamba x: df.count() if date and cod)
crist_9
  • 33
  • 4
  • `df = df.groupby(['date', 'cod', 'type'], sort=False).size().reset_index(name='count')` (as outlined in [this answer](/a/32801170/15497888)) – Henry Ecker Nov 15 '22 at 15:05
  • `df = df.value_counts().reset_index(name='count')` (as described in [this answer](/a/62802626/15497888)) – Henry Ecker Nov 15 '22 at 15:06

0 Answers0