Using .head() over .iloc[:]

I’m working through this

I knew the right answer but tried to use .head() instead. Is there a reason to choose one over the other? They both seem to create dataframes.

  1. 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[].

My Code:

# My Answer
top5_null_prev_rank = null_previous_rank.head(5)

# Course answer
top5_null_prev_rank = null_previous_rank.iloc[:5]

This has come up in the community before. Perhaps this post can answer your question:

Yep totally. .head() has far less versatility than .iloc[]. Thanks for the redirect :slight_smile:

1 Like