Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending Pandas dataframes row-wise

I have checked append and it should be doing the job, but for some reason I cannot figure out the row-wise append isn't working.

I have two dataframes with size (x,y). I want to combine these two row-wise, so the final dataframe is of size (2x,y).

I have tried to do the following:

frame_combined = frame_1.append(frame_2, ignore_header=True)
frame_combined = pd.concat([frame_1, frame_2], axis=1) # also axis=0

Edit: Doing these gives me a (2x,2y) dataframe. And also my dataframe has no header.

What am I missing that I get a dataframe that is appended both row and column-wise? And how can I do a simple row-wise append?

Thank you.

like image 376
madu Avatar asked Oct 29 '25 19:10

madu


1 Answers

There's a problem with your frame_2 headers being different from frame_1, this causes a misalignment, and if you're concatenating vertically, then your only option is to assign one to the other.

So do so,

frame_2.columns = frame_1.columns

Now concatenate:

frame_combined = pd.concat([frame_1, frame_2], ignore_index=True)
like image 147
cs95 Avatar answered Nov 01 '25 10:11

cs95



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!