df1 = pd.DataFrame({'Region': ['E', 'E', 'U', 'E'], 'Id': [1,None,None,None], 'Ids': [1,2,3,4]})
df2 = pd.DataFrame({'Region': ['E', 'U', 'U', 'E'], 'Id': [1,2,3,4], 'Ids': [1,2,3,4]})
x = df1.groupby(['Region']).count()
y = df2.groupby(['Region']).count()
c = pd.concat([x['Id'], y['Id']], axis=1, keys=['Here', 'There'])
I have the table with two rows (like indices, 'E' and 'U') which count the number of E and U for each data frame and concatenate them with different keys: Here and There. Now I want to add another index, let's call it 'Total' and next to it I want get the total number of values under 'Here' and 'There'.
Now:
Region | Here | There |
---|---|---|
E | 1 | 2 |
U | 0 | 2 |
Now I want to add another index, let's call it 'Total' and next to it I want get the total number of values under 'Here' and 'There'.
I want to achieve:
Region | Here | There |
---|---|---|
E | 1 | 2 |
U | 0 | 2 |
Total | 1 | 4 |
Thank you.