How do you merge or join DataFrames using inner, left, right, and outer joins?
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
How do you merge or join DataFrames using inner, left, right, and outer joins? Explain which rows each join type keeps, using two small DataFrames that share a key column.
```hint Trace a tiny example
Take left keys 1, 2, 3 and right keys 2, 3, 4. For each join type, write down which keys survive and which cells end up empty.
```
### What a Strong Answer Covers
- The pandas call and the argument that selects the join type
- Which rows each of the four join types keeps, and where missing values appear
- How `merge()` and `join()` differ in their defaults
- A way to audit the result of a join
- What happens when a key repeats on one or both sides
### Follow-up Questions
- How do you join on key columns that have different names, or on several columns at once?
- How does `merge()` treat `NaN` values in the key columns, and how is that different from SQL?
- How would you find the rows of the left DataFrame that have no match on the right?
- A left join returned more rows than the left DataFrame had. What happened, and how do you guard against it?
Overview: Asks how to combine two pandas DataFrames with inner, left, right and outer joins, and which rows each one keeps. Tests your command of the merge() and join() arguments, missing values in unmatched rows, and checks that catch duplicated keys.