Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Deleting a Row/Column | 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

bookDeleting a Row/Column

At times, certain columns may not provide valuable information, making it advantageous to remove them. The pandas library offers the drop() method for this purpose. Let's delve into the function's syntax.

  • index: Specifies the row indexes to be deleted (used when axis=0);
  • columns: Identifies the column names to be deleted (used when axis=1);
  • axis: Choose whether to remove labels from the rows (0) or columns (1). The default is 0.

In this section, we're going to work with a specific DataFrame. Let's examine it.

1234567
import pandas as pd dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : [None, None, 'Europe', None, 'Europe', None, 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pd.DataFrame(dataset) print(countries)
copy

We notice that the continent column contains numerous empty rows, making it less informative. Consequently, we'll remove it.

12345678
import pandas dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : [None, None, 'Europe', None, 'Europe', None, 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pandas.DataFrame(dataset) countries = countries.drop(columns = ['continent'],axis=1) print(countries)
copy

Time for some hands-on practice.

Tarefa
test

Swipe to show code editor

We have a DataFrame called audi_cars. Take a close look at the provided dictionary and eliminate the irrelevant column. Give it a try!

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

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

bookDeleting a Row/Column

At times, certain columns may not provide valuable information, making it advantageous to remove them. The pandas library offers the drop() method for this purpose. Let's delve into the function's syntax.

  • index: Specifies the row indexes to be deleted (used when axis=0);
  • columns: Identifies the column names to be deleted (used when axis=1);
  • axis: Choose whether to remove labels from the rows (0) or columns (1). The default is 0.

In this section, we're going to work with a specific DataFrame. Let's examine it.

1234567
import pandas as pd dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : [None, None, 'Europe', None, 'Europe', None, 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pd.DataFrame(dataset) print(countries)
copy

We notice that the continent column contains numerous empty rows, making it less informative. Consequently, we'll remove it.

12345678
import pandas dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : [None, None, 'Europe', None, 'Europe', None, 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pandas.DataFrame(dataset) countries = countries.drop(columns = ['continent'],axis=1) print(countries)
copy

Time for some hands-on practice.

Tarefa
test

Swipe to show code editor

We have a DataFrame called audi_cars. Take a close look at the provided dictionary and eliminate the irrelevant column. Give it a try!

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

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

bookDeleting a Row/Column

At times, certain columns may not provide valuable information, making it advantageous to remove them. The pandas library offers the drop() method for this purpose. Let's delve into the function's syntax.

  • index: Specifies the row indexes to be deleted (used when axis=0);
  • columns: Identifies the column names to be deleted (used when axis=1);
  • axis: Choose whether to remove labels from the rows (0) or columns (1). The default is 0.

In this section, we're going to work with a specific DataFrame. Let's examine it.

1234567
import pandas as pd dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : [None, None, 'Europe', None, 'Europe', None, 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pd.DataFrame(dataset) print(countries)
copy

We notice that the continent column contains numerous empty rows, making it less informative. Consequently, we'll remove it.

12345678
import pandas dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : [None, None, 'Europe', None, 'Europe', None, 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pandas.DataFrame(dataset) countries = countries.drop(columns = ['continent'],axis=1) print(countries)
copy

Time for some hands-on practice.

Tarefa
test

Swipe to show code editor

We have a DataFrame called audi_cars. Take a close look at the provided dictionary and eliminate the irrelevant column. Give it a try!

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

At times, certain columns may not provide valuable information, making it advantageous to remove them. The pandas library offers the drop() method for this purpose. Let's delve into the function's syntax.

  • index: Specifies the row indexes to be deleted (used when axis=0);
  • columns: Identifies the column names to be deleted (used when axis=1);
  • axis: Choose whether to remove labels from the rows (0) or columns (1). The default is 0.

In this section, we're going to work with a specific DataFrame. Let's examine it.

1234567
import pandas as pd dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : [None, None, 'Europe', None, 'Europe', None, 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pd.DataFrame(dataset) print(countries)
copy

We notice that the continent column contains numerous empty rows, making it less informative. Consequently, we'll remove it.

12345678
import pandas dataset = {'country' : ['Thailand', 'Philippines', 'Monaco', 'Malta', 'Sweden', 'Paraguay', 'Latvia'], 'continent' : [None, None, 'Europe', None, 'Europe', None, 'Europe'], 'capital':['Bangkok', 'Manila', 'Monaco', 'Valletta', 'Stockholm', 'Asuncion', 'Riga']} countries = pandas.DataFrame(dataset) countries = countries.drop(columns = ['continent'],axis=1) print(countries)
copy

Time for some hands-on practice.

Tarefa
test

Swipe to show code editor

We have a DataFrame called audi_cars. Take a close look at the provided dictionary and eliminate the irrelevant column. Give it a try!

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 1. Capítulo 9
Switch to desktopMude 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