简体   繁体   English

如何访问熊猫数据透视表数据

[英]How to access Pandas pivot-table data

I have this pivot table: 我有这个数据透视表:

d = c.pivot_table(index=[ 'Material'], columns = ['MvT'], values=['Quantity'], aggfunc=[np.sum],fill_value=0, margins = True)

sum
Quantity
  MvT       601  631  641   All
  Material              
 Type_A      9    2    5    16
 Type_B      6    4    10   20
 Type_C      3    0    2     5
 Type_D      3    2    1     6
 Type_E      1    0    1     2

  All       22    8   19    49

I want to display by matplotlib BAR 'All'. 我想通过matplotlib BAR'All'显示。 How can I access to 'All'? 如何访问“全部”?

d.loc[:,'All']

doesn't work 不起作用

KeyError: 'All'

Change [np.sum] to np.sum , you create a multiple index [np.sum]更改为np.sum ,创建多个索引

d = c.pivot_table(index='Material', columns = 'MvT', values='Quantity', aggfunc=np.sum,fill_value=0, margins = True)

then 然后

d.loc[:,'All']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM