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
  • 146,074
  • 10
  • 56
  • 74
Nishant
  • 105
  • 9

0 Answers0