0

I have a dataframe:

d={'year':['2011','2011','2011','2012','2012','2013','2013'],'sex':['M','F','M','M','F','F','M']}

df=pd.DataFrame(d)

I want to create new column for performing time series analysis, count of male and female each year. Output should be a dataframe like below:

enter image description here

I tried d1.groupby(['sex','year']).count(), but it did not do what i expected in output

Quang Hoang
  • 131,600
  • 10
  • 43
  • 63
Nishant
  • 95
  • 8

0 Answers0