Sometimes the keys for merging dataframes are located in the dataframes index. In such a situation, we can pass left_index=True or right_index=True to indicate that the index should be accepted as the merge key.
Merging on index is done in the following steps:
- Consider the following two dataframes:
left1 = pd.DataFrame({'key': ['apple','ball','apple', 'apple', 'ball', 'cat'], 'value': range(6)})right1 = pd.DataFrame({'group_val': [33.4, 5]}, index=['apple', 'ball'])
If you print these two dataframes, the output looks like the following screenshot:
Note that the keys in the first dataframe are apple, ball, and cat. In the ...