【发布时间】:2019-03-28 01:20:02
【问题描述】:
我正在尝试使用 pandas 旋转来获得小计。我不知道为什么我只得到列小计?
data = {'TypeOfInvestor':['Stocks', 'Bonds', 'Real Estate'],
'InvestorA': [96, 181, 88],
'InvestorB': [185, 3, 152],
'InvestorC': [39, 29, 142]}
df = pd.DataFrame(data)
pt = pd.pivot_table(df, values=['InvestorA', 'InvestorB', 'InvestorC'],
index=['TypeOfInvestor'],
aggfunc=np.sum, margins=True, margins_name='Total')
我希望使用 pivot_table 获得列的小计和行的小计,但我只得到列的小计。
【问题讨论】: