0

Below is my Data.

CompanyEvents   StartDate:year
Event1              2013
Event1              2013
Event1              2011
Event1              2011
Event1              2012
Event2              2015
Event2              2016
Event2              2016
Event2              2017

I want result is like table below. It should give count of repeating years of same event.

CompanyEvents   StartDate:year  StartDate:year_count
Event1          2013                 2
Event1          2013                 2
Event1          2011                 2
Event1          2011                 2
Event1          2012                 1
Event2          2015                 1
Event2          2013                 1
Event2          2016                 2
Event2          2017                 1
Event3          2011                 1
Prime coder
  • 89
  • 10

1 Answers1

0

There you go, using groupby and transform :

Pandas GroupBy Transform

df['StartDate:year_count'] = df.groupby('StartDate:year')['StartDate:year'].transform('count')
Ibrahim Ayoup
  • 377
  • 1
  • 12