How to merge two dataframes side-by-side?

You can use the concat function for this (axis=1 is to concatenate as columns):

pd.concat([df1, df2], axis=1)

See the pandas docs on merging/concatenating: http://pandas.pydata.org/pandas-docs/stable/merging.html


I came across your question while I was trying to achieve something like the following:

Merge dataframe sideways

So once I sliced my dataframes, I first ensured that their index are the same. In your case both dataframes needs to be indexed from 0 to 29. Then merged both dataframes by the index.

df1.reset_index(drop=True).merge(df2.reset_index(drop=True), left_index=True, right_index=True)

If you want to combine 2 data frames with common column name, you can do the following:

df_concat = pd.merge(df1, df2, on='common_column_name', how='outer')

I found that the other answers didn't cut it for me when coming in from Google.

What I did instead was to set the new columns in place in the original df.

# list(df2.columns) gives you the column names of df2
# you then use these as the column names for df

df[ list(df2.columns) ] = df2