0
0
Pandasdata~10 mins

merge() for SQL-like joins 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 merge two DataFrames on the 'id' column.

Pandas
merged_df = df1.merge(df2, on=[1])
Drag options to blanks, or click blank then click option'
A'name'
B'age'
C'id'
D'score'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column that does not exist in both DataFrames.
Using a column that is not unique or relevant for merging.
2fill in blank
medium

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

Pandas
result = df_left.merge(df_right, on=[1], how=[2])
Drag options to blanks, or click blank then click option'
A'customer_id'
B'user_id'
C'product_id'
D'order_id'
E'left'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name for the join key.
Forgetting to specify the join type for a left join.
3fill in blank
hard

Fix the error in the merge code to join on columns with different names: 'id_left' and 'id_right'.

Pandas
merged = df1.merge(df2, left_on=[1], right_on=[2])
Drag options to blanks, or click blank then click option'
A'id_left'
B'id_right'
C'id'
D'user_id'
Attempts:
3 left
💡 Hint
Common Mistakes
Using only 'on' when column names differ.
Mixing up left_on and right_on values.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Pandas
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword.startswith('a')
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using the wrong condition in the if clause.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts if count is greater than 1.

Pandas
{ [1]: [2] for [3], count in word_counts.items() if count > 1 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bcount
Cword
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the key without converting to uppercase.
Mixing up the key and value in the comprehension.