Appending Pandas dataframes row-wise
12,477
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)
Related videos on Youtube
Author by
madu
Updated on June 14, 2022Comments
-
madu almost 2 years
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.
-
jezrael almost 6 yearsIs possible add some data sample and expected output?
-
cs95 almost 6 yearsTry
frame_2.columns = frame_1.columns; df = pd.concat([frame_1, frame_2], ignore_index=True)
-
madu almost 6 years@coldspeed Thank you. It worked. Would you mind explaining what that did and why the usual append would not work?
-