Pandas Dataframe Vertical Merge
I have a query regarding merging two dataframes For example i have 2 dataframes as below : print(df1) Year Location 0 2013 america 1 2008 usa 2 2011
Solution 1:
It's the same columns and same order, so that you can use: df1.append(df2)
Solution 2:
Simply specify the axis along which to concatenate (axis=1
) in pd.concat
:
df_merged=pd.concat([df1,df2],axis=1)
Solution 3:
pd.concat([df1, df2])
should work. If all the column headings are the same, it will bind the second dataframe's rows below the first. This graphic from a pandas cheat sheet (https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf) explains it pretty well:
Post a Comment for "Pandas Dataframe Vertical Merge"