How can I convert these dataframe indexes into a column?

1189 views python
4

This is a dataframe with data of military spending for some countries from 2010-2017. I would to convert the years row of the dataframe: enter image description here

into a column with the name "Year" and another one with the values corresponding to each year for each country. It should look like this dataframe (ignore name of third column, it's just an example):

enter image description here

answered question

1 Answer

5

Using

df.reset_index().melt('Country')

posted this

Have an answer?

JD

Please login first before posting an answer.