0
0
Pandasdata~10 mins

Merging on index 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 their indexes.

Pandas
merged = df1.merge(df2, left_index=[1], right_index=True)
Drag options to blanks, or click blank then click option'
AFalse
BNone
CTrue
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using left_index=False will not merge on the index.
Forgetting to set right_index=True if merging on both indexes.
2fill in blank
medium

Complete the code to merge two DataFrames on their indexes with an outer join.

Pandas
merged = df1.merge(df2, left_index=True, right_index=True, how=[1])
Drag options to blanks, or click blank then click option'
A'inner'
B'outer'
C'left'
D'right'
Attempts:
3 left
💡 Hint
Common Mistakes
Using how='inner' excludes rows not matching in both DataFrames.
Forgetting to set left_index and right_index to True.
3fill in blank
hard

Fix the error in the code to merge two DataFrames on their indexes.

Pandas
merged = df1.merge(df2, left_index=True, right_index=[1])
Drag options to blanks, or click blank then click option'
AFalse
BNone
C0
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting right_index to False or None causes merge to fail on index.
4fill in blank
hard

Fill both blanks to merge two DataFrames on their indexes using a left join.

Pandas
merged = df1.merge(df2, left_index=[1], right_index=[2], how='left')
Drag options to blanks, or click blank then click option'
ATrue
BFalse
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting either left_index or right_index to False will not merge on index.
5fill in blank
hard

Fill all three blanks to merge two DataFrames on their indexes with suffixes for overlapping columns.

Pandas
merged = df1.merge(df2, left_index=[1], right_index=[2], how=[3], suffixes=('_left', '_right'))
Drag options to blanks, or click blank then click option'
ATrue
BFalse
C'inner'
D'outer'
Attempts:
3 left
💡 Hint
Common Mistakes
Using False for index parameters prevents merging on indexes.
Using how='inner' excludes non-matching rows.