Locked lesson.
About this lesson
We discuss how to merge and join data frames together in this video.
Exercise files
Download this lesson’s related exercise files.
Concatenating, Merging, and Joining part 2.docx57.2 KB Concatenating, Merging, and Joining part 2 - Solution.docx
57.4 KB
Quick reference
Concatenating, Merging, and Joining part 2
Merging and Joining allow us to combine data based on the specific data in a DataFrame.
When to use
Use Merging when you have a column in common (like a key column). Use Joining when the dataFrames have different indexes.
Instructions
To Merge two or more dataframes based on a similar column (such as Key):
pd.merge(left_df, right_df, how='inner', on='Key')
To Join two or more dataframes with different row indexes:
left_df.join(right_df)
Hints & tips
- Merge: pd.merge(left_df, right_df, how='inner', on='Key')
- Join: left_df.join(right_df)
- Join Inner: left_df.join(right_df, how='inner')
- Join Outer: left_df.join(right_df, how='outer')
- Join Left: left_df.join(right_df, how='left')
- Join Right: left_df.join(right_df, how='join')
Lesson notes are only available for subscribers.