merge dataframe pandas by column code example

Example 1: merge two dataframes based on column

df_outer = pd.merge(df1, df2, on='id', how='outer')

df_outer

Example 2: how to merge two dataframes

df_merge_col = pd.merge(df_row, df3, on='id')

df_merge_col

Example 3: merge dataframe pandas

>>> df1.merge(df2, left_on='lkey', right_on='rkey')
  lkey  value_x rkey  value_y
0  foo        1  foo        5
1  foo        1  foo        8
2  foo        5  foo        5
3  foo        5  foo        8
4  bar        2  bar        6
5  baz        3  baz        7

Example 4: merge two columns pandas

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

Example 5: merge dataframe

In [46]: result = pd.merge(left, right, how="right", on=["key1", "key2"])

Example 6: merge two dataframes based on column

df_merge_col = pd.merge(df_row, df3, on='id')

df_merge_col