<p><strong><em>您的数据透视表</em></strong></p>
<pre><code>table = pd.pivot_table(df, values=['Amount'],
index=['Location', 'Employee'],
columns=['Account', 'Currency'],
fill_value=0, aggfunc=np.sum, dropna=True, )
print(table)
Amount
Account Basic Net
Currency GBP USD GBP USD
Location Employee
Airport Test 2 0 3000 0 2000
Town Test 1 0 4000 0 3000
Test 3 5000 0 4000 0
</code></pre>
<hr/>
<h3><code>pandas.concat</code></h3>
<pre><code>pd.concat([
d.append(d.sum().rename((k, 'Total')))
for k, d in table.groupby(level=0)
]).append(table.sum().rename(('Grand', 'Total')))
Amount
Account Basic Net
Currency GBP USD GBP USD
Location Employee
Airport 2 0 3000 0 2000
Total 0 3000 0 2000
Town 1 0 4000 0 3000
3 5000 0 4000 0
Total 5000 4000 4000 3000
Grand Total 5000 7000 4000 5000
</code></pre>
<hr/>
<h3>旧答案</h3>
<p>为子孙后代</p>
<p><strong><em>生成小计</em></strong></p>
<pre><code>tab_tots = table.groupby(level='Location').sum()
tab_tots.index = [tab_tots.index, ['Total'] * len(tab_tots)]
print(tab_tots)
Amount
Account Basic Net
Currency GBP USD GBP USD
Location
Airport Total 0 3000 0 2000
Town Total 5000 4000 4000 3000
</code></pre>
<hr/>
<p><strong><em>一起</em></strong></p>
<pre><code>pd.concat(
[table, tab_tots]
).sort_index().append(
table.sum().rename(('Grand', 'Total'))
)
</code></pre>
<p><a href="https://i.stack.imgur.com/bKQNR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bKQNR.png" alt="enter image description here"/></a></p>