0
0
Pandasdata~10 mins

Setting a column as 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 set the 'Name' column as the index of the DataFrame.

Pandas
df = df.[1]('Name')
Drag options to blanks, or click blank then click option'
Areset_index
Bset_index
Cdrop
Drename
Attempts:
3 left
💡 Hint
Common Mistakes
Using reset_index instead of set_index.
Trying to rename the column instead of setting it as index.
2fill in blank
medium

Complete the code to set the 'ID' column as index without keeping it as a column.

Pandas
df = df.set_index('ID', [1]=True)
Drag options to blanks, or click blank then click option'
Adrop
Bkeep
Cinplace
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using keep=True which keeps the column.
Confusing inplace with drop.
3fill in blank
hard

Fix the error in the code to set 'Date' as index inplace.

Pandas
df.[1]('Date', inplace=True)
Drag options to blanks, or click blank then click option'
Aset_index
Breset_index
Cdrop
Drename
Attempts:
3 left
💡 Hint
Common Mistakes
Using reset_index which resets the index instead of setting it.
Trying to use drop as a method.
4fill in blank
hard

Fill both blanks to set 'User' as index and keep the column in the DataFrame.

Pandas
df = df.set_index([1], [2]=False)
Drag options to blanks, or click blank then click option'
A'User'
Bdrop
Ckeep
D'Name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using drop=True which removes the column.
Using the wrong column name.
5fill in blank
hard

Fill all three blanks to set 'Email' as index, drop the column, and do it inplace.

Pandas
df.[1]([2], drop=[3], inplace=True)
Drag options to blanks, or click blank then click option'
Aset_index
B'Email'
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using drop=False which keeps the column.
Not using inplace=True and expecting the DataFrame to change.