Recall & Review
beginner
What does
loc do when selecting rows in a DataFrame?loc selects rows by their labels or index names. It includes the last label in slicing.
Click to reveal answer
beginner
How does
iloc differ from loc when selecting rows?iloc selects rows by their integer position, starting at 0. It excludes the last index in slicing.
Click to reveal answer
beginner
What will
df.loc[2:4] return if the DataFrame index is [0, 1, 2, 3, 4, 5]?Rows with index labels 2, 3, and 4 inclusive.
Click to reveal answer
beginner
What will
df.iloc[2:4] return if the DataFrame index is [0, 1, 2, 3, 4, 5]?Rows at integer positions 2 and 3 (index labels 2 and 3), excluding position 4.
Click to reveal answer
intermediate
Can
loc select rows using boolean conditions?Yes, loc can select rows by passing a boolean mask (True/False values) to filter rows.
Click to reveal answer
Which method selects rows by integer position in a DataFrame?
✗ Incorrect
iloc selects rows by integer position, starting at 0.
What does
df.loc[1:3] include when selecting rows?✗ Incorrect
loc includes the last label in slicing, so rows 1, 2, and 3 are included.
If a DataFrame index is ['a', 'b', 'c', 'd'], what does
df.iloc[1:3] select?✗ Incorrect
iloc selects by position 1 and 2, which correspond to labels 'b' and 'c'.
Which of these is true about
loc slicing?✗ Incorrect
loc includes the last label when slicing rows.
How can you select rows where a column 'age' is greater than 30 using
loc?✗ Incorrect
Use a boolean mask inside loc to filter rows by condition.
Explain the difference between
loc and iloc when selecting rows in a DataFrame.Think about how you pick rows by name versus by number.
You got /4 concepts.
Describe how to select rows based on a condition using
loc.Use True/False values to pick rows.
You got /4 concepts.