Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Indexation | s1
Practice
Projects
Quizzes & Challenges
Quizze
Challenges
/
Track DA with Py - Data Manipulation with pandas

bookIndexation

Swipe um das Menü anzuzeigen

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

Our following attribute 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:

However, we will start with the simplest implementation of the attribute iloc[], working with the following data set (below are its first five rows):

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.

Question

Replace the placeholders ___ in a code window with your code to answer the question below it.

12345
import pandas as pd data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/4bf24830-59ba-4418-969b-aaf8117d522e/people.csv') print(data.___) # CHANGE CODE HERE (to answer the question below) print(data.___) # CHANGE CODE HERE (to answer the question below)
copy

Note that the index of a first person is 0.

question mark

Extract the second and the last row in the code window above. What are the names of those persons?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 18

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Abschnitt 1. Kapitel 18
some-alt