0
0
Pandasdata~10 mins

Left join behavior in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to perform a left join of df1 and df2 on the 'key' column.

Pandas
result = df1.merge(df2, how=[1], on='key')
Drag options to blanks, or click blank then click option'
A'outer'
B'inner'
C'right'
D'left'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'inner' instead of 'left' will drop rows not matching in df2.
Using 'right' or 'outer' will change which rows are kept.
2fill in blank
medium

Complete the code to join df1 and df2 on columns 'key1' and 'key2' using a left join.

Pandas
result = df1.merge(df2, how='left', on=[1])
Drag options to blanks, or click blank then click option'
A'key'
B'key2'
C['key1', 'key2']
D['key']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string instead of a list for multiple keys.
Using incorrect column names.
3fill in blank
hard

Fix the error in the code to perform a left join on 'id' column.

Pandas
result = df1.merge(df2, how='[1]', on='id')
Drag options to blanks, or click blank then click option'
Aleftt
Bleft
Clef
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Typo in the join type string.
Using 'right' instead of 'left' changes the join behavior.
4fill in blank
hard

Fill both blanks to create a left join that adds suffix '_df2' to overlapping columns from df2.

Pandas
result = df1.merge(df2, how=[1], on='key', suffixes=([2], '_df2'))
Drag options to blanks, or click blank then click option'
A'left'
B'_df1'
C'_left'
D'_right'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong join type like 'right' or 'inner'.
Not providing suffixes or using wrong suffix format.
5fill in blank
hard

Fill all three blanks to left join df1 and df2 on 'key', keep all df1 rows, and fill missing values in 'value' column with 0.

Pandas
result = df1.merge(df2, how=[1], on=[2])
result['value'] = result['value'].fillna([3])
Drag options to blanks, or click blank then click option'
A'left'
B'key'
C0
D'value'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong join type like 'inner'.
Joining on wrong column name.
Not filling missing values or using wrong fill value.