A left join keeps all rows from the left table and adds matching rows from the right table. If no match is found, it fills with missing values (like NaN).
Click to reveal answer
beginner
What does a right join do?
A right join keeps all rows from the right table and adds matching rows from the left table. If no match is found, it fills with missing values.
Click to reveal answer
beginner
In pandas, which function and parameter do you use to perform a left join?
Use pd.merge(left_df, right_df, how='left', on='key_column') to do a left join on the key column.
Click to reveal answer
beginner
What happens to rows in the right table that do not match any row in the left table during a left join?
They are dropped because the left join keeps all rows from the left table only.
Click to reveal answer
intermediate
How is a right join different from an inner join?
A right join keeps all rows from the right table, even if no match exists in the left table. An inner join keeps only rows with matches in both tables.
Click to reveal answer
Which join keeps all rows from the left table and matches from the right?
ALeft join
BRight join
CInner join
DOuter join
✗ Incorrect
A left join keeps all rows from the left table and adds matching rows from the right.
In pandas, how do you specify a right join?
Ahow='left'
Bhow='right'
Chow='inner'
Dhow='outer'
✗ Incorrect
Use how='right' in pd.merge() to perform a right join.
What happens to unmatched rows in the right table during a left join?
AThey are dropped
BThey are kept with missing values
CThey become duplicates
DThey are merged with default values
✗ Incorrect
Unmatched rows in the right table are dropped in a left join.
Which join keeps all rows from both tables, filling missing matches with NaN?
ALeft join
BRight join
CInner join
DOuter join
✗ Incorrect
An outer join keeps all rows from both tables.
If you want only rows with matching keys in both tables, which join do you use?
ALeft join
BRight join
CInner join
DOuter join
✗ Incorrect
Inner join returns only rows with matching keys in both tables.
Explain in your own words what a left join does and give a real-life example.
Think about keeping all your friends and adding info about their pets if available.
You got /4 concepts.
Describe the difference between a left join and a right join with a simple analogy.
Imagine two lists: one is your shopping list (left), the other is what’s in the fridge (right).
You got /4 concepts.
Practice
(1/5)
1. What does a left join do when combining two tables in data analysis?
easy
A. Keeps all rows from both tables, matching or not.
B. Keeps all rows from the left table and adds matching rows from the right table.
C. Keeps only rows that match in both tables.
D. Keeps all rows from the right table and adds matching rows from the left table.
Solution
Step 1: Understand the role of the left table in a left join
A left join keeps every row from the left table regardless of matches in the right table.
Step 2: Understand how matching rows from the right table are added
Only rows from the right table that match the left table's keys are added; unmatched right rows are ignored.
Final Answer:
Keeps all rows from the left table and adds matching rows from the right table. -> Option B
Quick Check:
Left join = all left rows + matching right rows [OK]
Hint: Left join keeps all left rows, adds right matches [OK]
Common Mistakes:
Confusing left join with right join
Thinking left join keeps unmatched right rows
Believing left join only keeps matching rows
2. Which of the following is the correct syntax for a left join using pandas in Python?
easy
A. pd.merge(df1, df2, how='left', on='key')
B. pd.merge(df1, df2, how='right', on='key')
C. pd.join(df1, df2, how='left')
D. df1.left_join(df2, on='key')
Solution
Step 1: Recall pandas merge syntax for joins
In pandas, the function to join tables is pd.merge(), specifying the join type with the 'how' parameter.
Step 2: Identify the correct parameters for a left join
Using how='left' and on='key' correctly performs a left join on the specified key column.
Final Answer:
pd.merge(df1, df2, how='left', on='key') -> Option A
Quick Check:
pd.merge + how='left' = left join [OK]
Hint: Use pd.merge with how='left' for left join [OK]