熊猫pivot_table:枢轴字符串

时间:2019-07-30 08:49:15

标签: python pandas

简单的例子:

d=pd.DataFrame({'brand':['xiaomi','apple','bana'],
                'type1':['a','b','c'],
                'type2':['e','f','g']})
d
Out[114]: 
    brand type1 type2
0  xiaomi     a     e
1   apple     b     f
2    bana     c     g

我想要的是:

brand  a b c
xiaomi e 
apple    f
bana       g

所以我用这个:

pd.pivot_table(d,index='brand',columns='type1',values='type2')

但是似乎不能将字符串设置为值。

0 个答案:

没有答案