Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to reset the index of the DataFrame df.
Pandas
df = 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 removes columns, not reset index.✗ Incorrect
The
reset_index() method resets the index of the DataFrame to the default integer index.2fill in blank
mediumComplete the code to reset the index of df and drop the old index.
Pandas
df = 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 in place but does not drop the old index.Using
append=True which adds the old index as a new level.✗ Incorrect
The
drop=True argument removes the old index instead of adding it as a column.3fill in blank
hardFix the error in the code to reset the index of df without adding the old index as a column.
Pandas
df.reset_index([1]=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
inplace=True alone does not drop the old index column.Using
append=True adds the old index as a new level.✗ Incorrect
To avoid adding the old index as a column, use
drop=True in reset_index().4fill in blank
hardFill both blanks to reset the index of df in place and drop the old index.
Pandas
df.reset_index([1]=True, [2]=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing
append with drop.Forgetting to set
inplace=True when wanting to modify the DataFrame directly.✗ Incorrect
Use
inplace=True to modify df directly and drop=True to remove the old index column.5fill in blank
hardFill all three blanks to reset the index of df, drop the old index, and keep the changes in place.
Pandas
df.reset_index([1]=True, [2]=True, [3]=False)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
append=True which adds the old index as a new column.Not understanding the purpose of
verify_integrity argument.✗ Incorrect
Use
inplace=True to modify df directly, drop=True to remove the old index, and verify_integrity=False to skip index integrity check.