小编Bre*_*ean的帖子

熊猫:使用多索引数据进行透视

我有两个数据帧,如下所示:

rating
   BMW  Fiat  Toyota
0    7     2       3
1    8     1       8
2    9    10       7
3    8     3       9

own
   BMW  Fiat  Toyota
0    1     1       0
1    0     1       1
2    0     0       1
3    0     1       1
Run Code Online (Sandbox Code Playgroud)

我最终想获得的数据透视表的平均得分使用品牌.或类似的东西:

            BMW  Fiat  Toyota
Usage                        
0      8.333333    10       3
1      7.000000     2       8
Run Code Online (Sandbox Code Playgroud)

我的方法是合并这样的数据集:

Measure  Rating                Own              
Brand       BMW  Fiat  Toyota  BMW  Fiat  Toyota
0             7     2       3    1     1       0
1             8 …
Run Code Online (Sandbox Code Playgroud)

python pivot-table pandas

8
推荐指数
1
解决办法
5933
查看次数

标签 统计

pandas ×1

pivot-table ×1

python ×1