course content

Course Content

Advanced Techniques in pandas

Learn More About IndexationLearn More About Indexation

Let's move further and continue extracting columns and rows by indices. So, you need to be familiar with a function similar to loc[].

Our following function is iloc[]; it is like index-location, and you may have guessed that it allows us to work with both columns' and rows' indices.

Firstly, we need to recall indices. The first row has the index 0, the next one 1, the next 2, and so on. But also, we can count from the end (indeed, this is not convenient in datasets, but it may be helpful somehow), so the last one has the index -1, the second-to-last is -2, and so on...

Look at the table:

Index from the BeginningRows in DatasetIndex from the End

However, we will start with the simplest implementation of the function iloc[], working with the same data set.

Look to the code example and output:

  • data.iloc[0] - extracts the very first row of the dataset.
  • data.iloc[1] - extracts the second row of the dataset.
  • data.iloc[-1] - extracts the very last row of the dataset.
  • data.iloc[-2] - extracts the second-to-last row of the dataset.

As you may have recognized, at the end of the output, the variable Name shows the row number too, like Name: 998.

Your task here is to fill in the gaps to output the required rows of the dataset (please, don't put spaces in your answer):

# Extract the eighth row of the dataset
# Extract the first row of the dataset

# Extract the 90th row of the dataset

Section 1.

Chapter 4