Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to reset the MultiIndex of the DataFrame df to columns.
Pandas
df_reset = df.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
set_index() instead of reset_index().Trying to use
drop() which is unrelated here.✗ Incorrect
The
reset_index() method moves the MultiIndex levels back to columns in the DataFrame.2fill in blank
mediumComplete the code to reset the MultiIndex and drop the old index from the DataFrame df.
Pandas
df_reset = df.reset_index([1]=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
inplace=True which modifies the DataFrame but does not drop the index.Confusing
level parameter with dropping the index.✗ Incorrect
Setting
drop=True in reset_index() removes the old index instead of adding it as columns.3fill in blank
hardFix the error in the code to reset only the first level of the MultiIndex in df.
Pandas
df_reset = df.reset_index(level=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like 'first' which is not valid for the level parameter.
Passing a list instead of a single level.
✗ Incorrect
The
level parameter accepts an integer index of the level to reset. Using 0 resets the first level.4fill in blank
hardFill both blanks to reset the MultiIndex and keep the changes in the original DataFrame df.
Pandas
df.[1](inplace=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
set_index which does the opposite.Setting
inplace=False which returns a new DataFrame instead of modifying df.✗ Incorrect
Using
reset_index with inplace=True resets the MultiIndex and updates df directly.5fill in blank
hardFill all three blanks to reset the MultiIndex of df, drop the old index, and reset only the second level.
Pandas
df_reset = df.reset_index(level=[1], [2]=[3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
inplace=True which modifies the original DataFrame instead of returning a new one.Resetting the wrong level index.
✗ Incorrect
Resetting level 1 with
drop=True removes the old index from the result. inplace is not used here.