Is a left merge just a right merge but switching the order of the dataframes?

Question

In the context of this exercise, is a left merge just a right merge but switching the order of the dataframes?

Answer

Yes, a left merge is the reverse of a right merge, and you can essentially perform either by switching the order of dataframes and using the other type of merge.

For example, these will produce the same results.
df1.merge(df2, how='left')
and
df2.merge(df1, how='right')

The only difference would be the order of the resulting dataframe, for the columns and for the rows which will preserve the order of the left keys.

3 Likes