Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Using iloc | The Very First Steps
Pandas First Steps
course content

Conteúdo do Curso

Pandas First Steps

Pandas First Steps

1. The Very First Steps
2. Reading Files in Pandas
3. Analyzing the Data

Using iloc

The DataFrame we are working with:

In the DataFrame we're working with, you can also use negative indexing. Negative indexing starts from the end of the DataFrame: index -1 points to the last row, -2 to the second to last, and so on.

To access the seventh row (which refers to Latvia), you can use either index 6 or -1. Let's see how this works in practice.

123456
import pandas dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : ['Asia', 'Asia', 'Europe', 'Europe', 'Europe', 'South America', 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pandas.DataFrame(dataset) # Accessing to the seventh row using negative indexing print(countries.iloc[-1])
copy

Running the above code will return the row highlighted in the image below:

It's time to practice!

Tarefa

We have a DataFrame called audi_cars.

  1. Display all the details from the DataFrame for the Audi A1 model from the year 2017. To do this, you'll need to use positive indexing.
  2. Display all the details from the DataFrame for the Audi A1 model from the year 2016 using negative indexing.
  3. Display all the details from the DataFrame for the Audi A3 model using positive indexing.

Make sure to use the iloc attribute. Give it a try!

Task Table

Tarefa

We have a DataFrame called audi_cars.

  1. Display all the details from the DataFrame for the Audi A1 model from the year 2017. To do this, you'll need to use positive indexing.
  2. Display all the details from the DataFrame for the Audi A1 model from the year 2016 using negative indexing.
  3. Display all the details from the DataFrame for the Audi A3 model using positive indexing.

Make sure to use the iloc attribute. Give it a try!

Task Table

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 1. Capítulo 14
toggle bottom row

Using iloc

The DataFrame we are working with:

In the DataFrame we're working with, you can also use negative indexing. Negative indexing starts from the end of the DataFrame: index -1 points to the last row, -2 to the second to last, and so on.

To access the seventh row (which refers to Latvia), you can use either index 6 or -1. Let's see how this works in practice.

123456
import pandas dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : ['Asia', 'Asia', 'Europe', 'Europe', 'Europe', 'South America', 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pandas.DataFrame(dataset) # Accessing to the seventh row using negative indexing print(countries.iloc[-1])
copy

Running the above code will return the row highlighted in the image below:

It's time to practice!

Tarefa

We have a DataFrame called audi_cars.

  1. Display all the details from the DataFrame for the Audi A1 model from the year 2017. To do this, you'll need to use positive indexing.
  2. Display all the details from the DataFrame for the Audi A1 model from the year 2016 using negative indexing.
  3. Display all the details from the DataFrame for the Audi A3 model using positive indexing.

Make sure to use the iloc attribute. Give it a try!

Task Table

Tarefa

We have a DataFrame called audi_cars.

  1. Display all the details from the DataFrame for the Audi A1 model from the year 2017. To do this, you'll need to use positive indexing.
  2. Display all the details from the DataFrame for the Audi A1 model from the year 2016 using negative indexing.
  3. Display all the details from the DataFrame for the Audi A3 model using positive indexing.

Make sure to use the iloc attribute. Give it a try!

Task Table

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 1. Capítulo 14
toggle bottom row

Using iloc

The DataFrame we are working with:

In the DataFrame we're working with, you can also use negative indexing. Negative indexing starts from the end of the DataFrame: index -1 points to the last row, -2 to the second to last, and so on.

To access the seventh row (which refers to Latvia), you can use either index 6 or -1. Let's see how this works in practice.

123456
import pandas dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : ['Asia', 'Asia', 'Europe', 'Europe', 'Europe', 'South America', 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pandas.DataFrame(dataset) # Accessing to the seventh row using negative indexing print(countries.iloc[-1])
copy

Running the above code will return the row highlighted in the image below:

It's time to practice!

Tarefa

We have a DataFrame called audi_cars.

  1. Display all the details from the DataFrame for the Audi A1 model from the year 2017. To do this, you'll need to use positive indexing.
  2. Display all the details from the DataFrame for the Audi A1 model from the year 2016 using negative indexing.
  3. Display all the details from the DataFrame for the Audi A3 model using positive indexing.

Make sure to use the iloc attribute. Give it a try!

Task Table

Tarefa

We have a DataFrame called audi_cars.

  1. Display all the details from the DataFrame for the Audi A1 model from the year 2017. To do this, you'll need to use positive indexing.
  2. Display all the details from the DataFrame for the Audi A1 model from the year 2016 using negative indexing.
  3. Display all the details from the DataFrame for the Audi A3 model using positive indexing.

Make sure to use the iloc attribute. Give it a try!

Task Table

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

The DataFrame we are working with:

In the DataFrame we're working with, you can also use negative indexing. Negative indexing starts from the end of the DataFrame: index -1 points to the last row, -2 to the second to last, and so on.

To access the seventh row (which refers to Latvia), you can use either index 6 or -1. Let's see how this works in practice.

123456
import pandas dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : ['Asia', 'Asia', 'Europe', 'Europe', 'Europe', 'South America', 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pandas.DataFrame(dataset) # Accessing to the seventh row using negative indexing print(countries.iloc[-1])
copy

Running the above code will return the row highlighted in the image below:

It's time to practice!

Tarefa

We have a DataFrame called audi_cars.

  1. Display all the details from the DataFrame for the Audi A1 model from the year 2017. To do this, you'll need to use positive indexing.
  2. Display all the details from the DataFrame for the Audi A1 model from the year 2016 using negative indexing.
  3. Display all the details from the DataFrame for the Audi A3 model using positive indexing.

Make sure to use the iloc attribute. Give it a try!

Task Table

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 1. Capítulo 14
Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt