Exploring Data With Pandas: Intermediate Q.6

Practice question:

Assign the first five rows of the null_previous_rank dataframe to the variable top5_null_prev_rank by choosing the correct method out of either loc[] or iloc[]

For the practice question above, why can’t I use the code below?(It returns an error)

top5_null_prev_rank = null_previous_rank.loc['48':'140']

You can, actually.

You just need do pass the labels as integers, not strings:

top5_null_prev_rank = null_previous_rank.loc[48:140]

That’s what it’s explained in this screen you refer to:

If we wanted to select a row using loc[] , we’d have to use the integer label for the first row — 48

Exactly! Thank you so much!

1 Like