I am trying to summarize subsec column by controlling year and ticker in the below table. Such that, a new column to be created and sum of df.subsec to be added here.
I tried this data science link by adjusting the code but it didnot work:
dfc['k']=dfc.groupby(['ticker', 'year'])['subsec'].sum().sum(level=['ticker', 'year'])
Modify a little the sum and use
reset_index to adjust the dataframe.
df = ( dfc.groupby(['ticker', 'year'])['subsec'] .sum() .reset_index(name='sumsss') )