I have a DF with the following structure:
| Level | Rate |
Indicator | AAA | BBB | CCC | XXX | YYY |
location variable |
One 2017 0.69 0.22 0.71 0.02 0.98
2018 0.31 0.15 0.78 0.03 0.96
2019 0.55 0.19 0.82 0.04 0.83
Two 2017 0.31 0.33 0.93 0.11 0.21
2018 0.24 0.35 0.01 0.12 0.14
2019 0.16 0.25 0.12 0.14 0.17
Three 2017 0.58 0.11 0.55 0.21 0.27
2018 0.75 0.10 0.68 0.22 0.25
2019 0.42 0.08 0.71 0.23 0.41
I need to get a DF the following structure (with only one level):
location | variable | Indicator | Level | Rate |
------------------------------------------------
One | 2017 | AAA | 0.69 | NaN |
...
Three | 2019 | YYY | NaN | 0.41 |
I've made several attempts like this below but they don't work:
df.melt(col_level=0, id_vars = ['Location','Indicator','variable'] , value_vars = ['Level', 'Rate'])
Any help would be highly appreciated