The following code generates the pandas table named out.
import pandas as pd
import numpy as np
df = pd.DataFrame({'Book': ['B1', 'B1', 'B2', 'B3', 'B3', 'B3'],
'Trader': ['T1', 'Z2', 'Z2', 'T1', 'U3', 'T2'],
'Position':[10, 33, -34, 87, 43, 99]})
df = df[['Book', 'Trader', 'Position']]
table = pd.pivot_table(df, index=['Book', 'Trader'], values=['Position'], aggfunc=np.sum)
print(table)
tab_tots = table.groupby(level='Book').sum()
tab_tots.index = [tab_tots.index, ['Total'] * len(tab_tots)]
print(tab_tots)
out = pd.concat(
[table, tab_tots]
).sort_index().append(
table.sum().rename(('Grand', 'Total'))
)
But I would like it to look like 
Notice how the second table always puts the 'Total' at the bottom. So basically I still want to sort alphabetically but I would like to always put 'Total' last. Could someone provide an adjustment to my code that gives my desired output?
