这看起来很简单,我简直不敢相信我在拉我的头发。 我有这样使用multiindex在pandas pivot_table上创建一个新列
Name income expenses 2015 2016 2015 2016 Joe Doe 2 4 5 7 Jane Doe 2 4 5 7 Doe Joe 2 4 5 7 Doe Jane 2 4 5 7
一个pivot_table我只是想添加一个计算列profit_loss =(收入 - 支出) 我认为这将是这样的:
df['profit_loss'] = df['income'] - df['expenses]
我只得到错误。
无需为创建此pivot_table的基表编写大量代码或准备,是否有更简单的方法来处理pandas pivot_table上的MultiIndexes
?
可你[文章](http://stackoverflow.com/posts/39581185/edit)'df.to_dict()'的输出,所以我们可以更容易地构建多索引DF? – MaxU