using the example from Pandas sum by groupby, but exclude certain columns
Code Country Item_Code Item Ele_Code Unit Y1961 Y1962 Y1963
2 Afghanistan 15 Wheat 5312 Ha 10 20 30
2 Afghanistan 25 Maize 5312 Ha 10 20 30
4 Angola 15 Wheat 7312 Ha 30 40 50
4 Angola 25 Maize 7312 Ha 30 40 50
when we do the
df.groupby(['Country', 'Item_Code'])[["Y1961", "Y1962", "Y1963"]].sum()
the output will be
Y1961 Y1962 Y1963
Country Item_Code
Afghanistan 15 10 20 30
25 10 20 30
Angola 15 30 40 50
25 30 40 50
Now , here is my questions
when I do df.columns
i will only get Y1961 Y1962 Y1963
But what if I want Country, Item_Code
are included as columns like below
df.columns
Country, Item_Code ,Y1961 Y1962 Y1963