我有一个数据帧,我想以某种方式进行转换,“attr”列的值变成列而不是值,而price保持为列
我曾尝试对列进行分组和转置,但没有找到一种方法来达到我想要的目的。这是我的数据集:
attr values price
0 Mærke Knauf Insulation 24.95
1 Produkttype Bygningsisolering 24.95
2 Serie SPACE 24.95
3 Model FORMSTYKKE 24.95
4 Mærke Bromiflex 20.00
5 Produkttype Rørskål 20.00
6 Materiale Opskummet polyethylen 20.00
7 Størrelse Ø18 MM 20.00
8 Mærke Skamowall 190.00
9 Produkttype Isoleringsplade 190.00
10 Serie BASIC 190.00
11 Materiale Brændt kalk og mikrosilika 190.00
12 Mærke Rockwool 210.00
13 Produkttype Bygningsisolering 210.00
14 Serie Terrænbatts 210.00
15 Materiale Stenuld 210.00
16 Mærke Knauf Insulation 65.00
17 Produkttype Isolering 65.00
我想要的是:
Mærke Produkttype Serie Model Materiale Størrelse Price
Knauf Insulation Bygningsisolering SPACE FORMSTYKKE NAN NAN 24.95
Bromiflex Rørskål NAN NAN Opskummet polyethylen Ø18 MM 24.95
我从df.groupby([“attr”,“values”])[“price”].mean().reset_index().set_index(“attr”)开始,但没有得到想要的结构,这很可能涉及到数据集的转换
非常感谢您的帮助
相关问题 更多 >
编程相关推荐