I have a dataframe that I would like to transpose in a certain way, in which the "attr" column values become columns instead of values, while price stays as a column.
I have tried to group the columns and transpose it, but haven't found a way to get where I wanted. This is my dataset:
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
What I want is this:
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
I started with df.groupby(["attr", "values"])["price"].mean().reset_index().set_index("attr"), but didnt get the wanted structure, which most likely involves transposing the dataset.
Any help is highly appreciated!