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

pd.concat not stacking columns with same names

I’m in awe that this isn’t working because I’ve done this a hundred times. I want to stack two dataframes vertically and pandas is creating duplicate columns and refusing to put the data in the right columns.

df1 looks like this:

enter image description here

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

df2 looks like this:

enter image description here

then I run this:

frames = [df1,df2]
final = pd.concat(frames, ignore_index = True, axis = 0)
final

and get 6 columns instead of 3 like this:

enter image description here

I have no idea why two dataframes with identical column names and data types would not simply stack on top of each other. Any help appreciated.

Thanks.

update: this is with axis = 1

enter image description here

>Solution :

Try

#  make axis=1

final = pd.concat(frames,   axis = 0)
final
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