0
0
Pandasdata~10 mins

Why indexing matters in Pandas - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the first row of the DataFrame using .iloc.

Pandas
first_row = df.[1][0]
Drag options to blanks, or click blank then click option'
Ailoc
Bat
Cloc
Diat
Attempts:
3 left
💡 Hint
Common Mistakes
Using loc instead of iloc causes errors if index labels are not integers.
Using at or iat requires scalar access, not slicing.
2fill in blank
medium

Complete the code to set the 'id' column as the DataFrame index.

Pandas
df = df.[1]('id')
Drag options to blanks, or click blank then click option'
Aset_index
Brename
Creset_index
Ddrop
Attempts:
3 left
💡 Hint
Common Mistakes
Using reset_index removes the current index instead of setting a new one.
Using drop or rename does not change the index.
3fill in blank
hard

Fix the error in the code to select rows where the index is greater than 5.

Pandas
filtered = df[df.index [1] 5]
Drag options to blanks, or click blank then click option'
A<=
B==
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' selects only index equal to 5, not greater.
Using '<=' selects index less than or equal to 5.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Pandas
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters words shorter than 3 characters.
Using 'word' instead of len(word) gives the word itself, not its length.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase keys and values greater than zero.

Pandas
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() creates lowercase keys instead of uppercase.
Using '<' or '!=' in the condition filters wrong values.