I have two dataframes which looks like this:
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
I'm ultimately trying to get a pivot table of mean rating for usage by brand. Or something like this:
BMW Fiat Toyota
Usage
0 8.333333 10 3
1 7.000000 2 8
My approach was to merge the datasets like this:
Measure Rating Own
Brand BMW Fiat Toyota BMW Fiat Toyota
0 7 2 3 1 1 0
1 8 1 8 0 1 1
2 9 10 7 0 0 1
3 8 3 9 0 1 1
And then attempt to create a pivot table using rating as the value, own as the rows and brand as the columns. But I kept running to key issues. I have also attempted unstacking either the measure or brand levels, but I can't seem to use row index names as pivot keys.
What am I doing wrong? Is there a better approach to this?