An inner join returns only the rows where the key exists in both DataFrames. It combines matching rows based on the join key.
Click to reveal answer
beginner
Which pandas function is used to perform an inner join?
The pandas function merge() is used with the parameter how='inner' to perform an inner join.
Click to reveal answer
intermediate
If DataFrame A has 5 rows and DataFrame B has 4 rows, how many rows can the inner join result have at most?
The inner join result can have at most the number of rows that have matching keys in both DataFrames, so it will be less than or equal to 4 (the smaller DataFrame's row count).
Click to reveal answer
beginner
What happens to rows in pandas inner join if the key is missing in one DataFrame?
Rows with keys missing in either DataFrame are excluded from the result. Only rows with keys present in both DataFrames appear.
Click to reveal answer
beginner
How can you specify the columns to join on in pandas inner join?
Use the on parameter in merge() to specify the column(s) to join on, e.g., pd.merge(df1, df2, on='key', how='inner').
Click to reveal answer
What does how='inner' do in pandas merge()?
AReturns only rows with matching keys in both DataFrames
BReturns all rows from the left DataFrame
CReturns all rows from the right DataFrame
DReturns all rows from both DataFrames
✗ Incorrect
Inner join returns only rows where the join key exists in both DataFrames.
If a key exists only in the left DataFrame, will it appear in the inner join result?
AYes, always
BOnly if specified with <code>left_on</code>
COnly if <code>how='outer'</code> is used
DNo, never
✗ Incorrect
Inner join excludes rows with keys missing in either DataFrame.
Which parameter specifies the join columns in pandas merge()?
Aon
Bcolumns
Cjoin_cols
Dkeys
✗ Incorrect
The on parameter specifies the column(s) to join on.
What is the default join type in pandas merge()?
Aouter
Bleft
Cinner
Dright
✗ Incorrect
The default join type for merge() is inner.
If DataFrame A has 3 matching keys with DataFrame B, how many rows will the inner join have?
AMore than 3
B3
CLess than 3
DCannot be determined
✗ Incorrect
Inner join returns rows only for matching keys, so the result will have 3 rows.
Explain how an inner join works in pandas and what happens to rows without matching keys.
Think about which rows appear in the result when keys match or don't match.
You got /3 concepts.
Describe how to perform an inner join on two pandas DataFrames using a specific column.
Focus on the function and parameters needed.
You got /3 concepts.
Practice
(1/5)
1. What does an inner join do when merging two pandas DataFrames?
easy
A. Keeps only rows with matching keys in both DataFrames
B. Keeps all rows from the left DataFrame and fills missing with NaN
C. Keeps all rows from the right DataFrame and fills missing with NaN
D. Keeps all rows from both DataFrames, filling missing with NaN
Solution
Step 1: Understand join types in pandas
Inner join keeps only rows where the key exists in both DataFrames.
Step 2: Compare with other join types
Left join keeps all left rows, right join keeps all right rows, outer join keeps all rows from both.
Final Answer:
Keeps only rows with matching keys in both DataFrames -> Option A
Quick Check:
Inner join = matching keys only [OK]
Hint: Inner join keeps only common keys in both tables [OK]
Common Mistakes:
Confusing inner join with left or outer join
Thinking inner join keeps all rows
Assuming inner join fills missing with NaN
2. Which of the following is the correct syntax to perform an inner join on DataFrames df1 and df2 using the column 'id'?
easy
A. pd.merge(df1, df2, on='id', how='inner')
B. pd.merge(df1, df2, on='id', how='outer')
C. df1.join(df2, on='id')
D. df1.merge(df2, left_on='id', right_on='id', how='left')
Solution
Step 1: Identify correct function and parameters
Use pd.merge() with on='id' and how='inner' for inner join.
Step 2: Check other options for errors
df1.join(df2, on='id') defaults to left join, pd.merge(df1, df2, on='id', how='outer') uses outer join, df1.merge(df2, left_on='id', right_on='id', how='left') uses left join.
Final Answer:
pd.merge(df1, df2, on='id', how='inner') -> Option A