0
0
Data Analysis Pythondata~10 mins

Selecting rows (loc, iloc) in Data Analysis Python - Interactive Code Practice

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

Complete the code to select the row with label 2 using loc.

Data Analysis Python
selected_row = df.loc[[1]]
Drag options to blanks, or click blank then click option'
A2
Biloc[2]
Cdf[2]
D'2'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number when the index is integer.
Using iloc instead of loc.
2fill in blank
medium

Complete the code to select the third row using iloc.

Data Analysis Python
selected_row = df.iloc[[1]]
Drag options to blanks, or click blank then click option'
A3
B2
C'2'
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 2 for the third row.
Using loc instead of iloc.
3fill in blank
hard

Fix the code to select rows 1 to 3 (inclusive) using loc.

Data Analysis Python
subset = df.loc[[1]]
Drag options to blanks, or click blank then click option'
A1:3
B[1:3]
C1:4
D[1,3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1:4, confusing loc (inclusive end) with iloc (exclusive end).
Using list syntax instead of slice notation.
4fill in blank
hard

Fill both blanks to select rows with iloc from position 0 to 2 and columns 'A' and 'B'.

Data Analysis Python
subset = df.iloc[[1], [2]]
Drag options to blanks, or click blank then click option'
A0:3
B['A', 'B']
C[0, 1]
Dslice(0, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using column labels instead of positions with iloc.
Using list syntax for rows instead of slice.
5fill in blank
hard

Fill all three blanks to create a dictionary of row labels and values from column 'score' for rows where score > 50 using loc.

Data Analysis Python
result = {index: row[[1]] for index, row in df.loc[df[[2]] [3] 50].iterrows()}
Drag options to blanks, or click blank then click option'
A'score'
Bscore
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using score without quotes as a string key.
Using < instead of > for the condition.