import pandas as pd
decade = [1960, 1960, 1960, 1960, 1960, 1960, 1970, 1970, 1970, 1970, 1970, 1970, 1980, 1980, 1980, 1980]
gender = ['F', 'M', 'F', 'M', 'F', 'M', 'F', 'M', 'F', 'M', 'F', 'M', 'F', 'M', 'F', 'M']
births = [4192, 4198, 4710, 4850, 4646, 5092, 4800, 4934, 4126, 4324, 4758, 5076, 5070, 5296, 4798, 5096]
dataset = pd.DataFrame({
'decade': decade,
'gender': gender,
'births' : births
})
Попробуйте:
df = dataset.groupby(['gender', 'decade'])['births'].sum()
df = df.unstack(level=0)