pandas join two columns code example

Example 1: join on column pandas

# df1 as main df and use the feild from df2 and map it into df1

df1.merge(df2,on='columnName',how='left')

Example 2: pandas merge two columns from different dataframes

#suppose you have two dataframes df1 and df2, and 
#you need to merge them along the column id
df_merge_col = pd.merge(df1, df2, on='id')

Example 3: merge two columns name in one header pandas

df['A'] = df[a_cols].apply(' '.join, axis=1)

Example 4: merge two columns pandas

df["period"] = df["Year"] + df["quarter"]

Example 5: how to join two dataframe in pandas based on two column

merged_df = left_df.merge(right_df, how='inner', left_on=["A", "B"], right_on=["A2","B2"])

Example 6: how to merge two column pandas

DataFrame["new_column"] = DataFrame["column1"] + DataFrame["column2"]