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

Append multiple columns to single column

I have the following dataframe:

enter image description here

When I plot this, I get the following:

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

Plot

But what I want is that the values of all the columns should be appended to one single columns so that I can obtain just one single line.
I mean, there should be no column number 4,5,6,7. Just one single column with the values of all these.
My Problem:

  1. Not able to convert Index from month names to 0,1,2,3,. I have used Set_Index but it didnt work
  2. Used Append command with drop index but didn’t get any results.

I m just one day old in learning pandas. Kindly give me lead.

>Solution :

Try:

single_column_frame = pd.concat([df[col] for col in df.columns])

If you want to get rid of month names as well:

single_column_frame = single_column_frame.reset_index().drop(columns=['index'])

You can also do:

single_column_frame = df.stack().reset_index().loc[:,0]
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