Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas make columns to rows

I got a pandas dataframe which looks like the following picture:

enter image description here

Every year is a new column, but i want them in one column called year.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It should look similar like this dataframe:

enter image description here

Anybody got an idea, how i can achieve this?
Thanks!

>Solution :

you need to use the melt method, something like this

df2 = df.melt(id_vars=['country','continent'], var_name="year", value_vars=[str(x) for x in range(1850,2011)])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading