0
0
Data Analysis Pythondata~10 mins

merge() for SQL-style joins in Data Analysis Python - Interactive Code Practice

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

Complete the code to merge two DataFrames on the 'id' column.

Data Analysis Python
merged_df = df1.merge(df2, on=[1])
Drag options to blanks, or click blank then click option'
A'id'
B'name'
C'age'
D'score'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column that does not exist in both DataFrames.
Forgetting to put quotes around the column name.
2fill in blank
medium

Complete the code to perform a left join using merge().

Data Analysis Python
result = df1.merge(df2, on='id', how=[1])
Drag options to blanks, or click blank then click option'
A'left'
B'inner'
C'right'
D'outer'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'inner' instead of 'left' when you want to keep all left rows.
Misspelling the join type string.
3fill in blank
hard

Fix the error in the merge code to join on columns 'id' and 'date'.

Data Analysis Python
merged = df1.merge(df2, on=[1])
Drag options to blanks, or click blank then click option'
A('id', 'date')
B'id, date'
C['id', 'date']
D'id date'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string with commas instead of a list.
Using parentheses instead of square brackets.
4fill in blank
hard

Fill both blanks to merge df1 and df2 on 'user_id' with an outer join.

Data Analysis Python
merged_df = df1.merge(df2, on=[1], how=[2])
Drag options to blanks, or click blank then click option'
A'user_id'
B'left'
C'outer'
D'right'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' or 'right' instead of 'outer' for full join.
Forgetting quotes around column names.
5fill in blank
hard

Fill all three blanks to merge on 'key', keep only matching rows, and suffix overlapping columns with '_left' and '_right'.

Data Analysis Python
merged = df1.merge(df2, on=[1], how=[2], suffixes=([3], '_right'))
Drag options to blanks, or click blank then click option'
A'key'
B'inner'
C'_left'
D'_common'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'outer' or 'left' instead of 'inner' when only matching rows are needed.
Not providing suffixes or using incorrect suffix strings.