BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

Pd.merge() parameters

screen link: https://app.dataquest.io/m/346/working-with-strings-in-pandas/1/introduction

merged = pd.merge(left=happiness2015, right=world_dev, how=‘left’, left_on=‘Country’, right_on=‘ShortName’)

Could somebody explain what left_on and right_on parameters do here?
I have looked through documentation , but could not figure out.

Thank you very much beforehand!

Column names to join on in the left DataFrame and right DataFrame respectively.

Check documentation

The columns used in a merge operator do not need to be named the same in both the left and right dataframe. In the second merge above, note that the device ID is called “device” in the left dataframe, and called “Model” in the right dataframe.

Different column names are specified for merges in Pandas using the “left_on” and “right_on” parameters, instead of using only the “on” parameter.

source: https://www.shanelynn.ie/merge-join-dataframes-python-pandas-index-1/#differentnames

1 Like