Guillermina
Guillermina

Reputation: 3657

How can I convert these dataframe indexes into a column?

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

Upvotes: 0

Views: 50

Answers (1)

BENY
BENY

Reputation: 323306

Using

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

Upvotes: 4

Related Questions