数据透视表:透视字符串

2024-10-02 04:25:31 发布

您现在位置:Python中文网/ 问答频道 /正文

简单示例:

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')

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


Tags: columns示例appledataframeindextableoutpd

热门问题