Pandas: Merge Two Data Frames on Multiple Columns

Last Updated On Tuesday 5th Oct 2021

Pandas Merge on Multiple Columns

As Per Docs

left_on

  • left_on – label or list, or array-like Column or index level names to join on in the left DataFrame.
  • Can also be an array or list of arrays of the length of the left DataFrame.
  • These arrays are treated as if they are columns.

right_on

  • right_on – label or list, or array-like Column or index level names to join on in the right DataFrame.
  • Can also be an array or list of arrays of the length of the right DataFrame.
  • These arrays are treated as if they are columns.

pandas join on multiple columns

	new_df = pd.merge(A_df, B_df,  how='left', left_on=['A_c1','c2'], right_on = ['B_c1','c2'])
	

PD Merge on Multiple Columns

Another way

	new_df = A_df.merge(B_df, left_on=['A_c1','c2'], right_on = ['B_c1','c2'], how='left')