Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Deleting a Row/Column | The Very First Steps
Pandas First Steps
course content

Kurssisisältö

Pandas First Steps

Pandas First Steps

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

book
Deleting 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.

python
  • 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.

We'll start by examining the DataFrame:

1234567
import pandas as pd countries_data = {'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(countries_data) print(countries)
copy

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

12345678
import pandas countries_data = {'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(countries_data) countries = countries.drop(columns = ['continent'],axis=1) print(countries)
copy
Tehtävä

Swipe to start coding

You are given a DataFrame named audi_cars.

  • Remove the 'capital' column and save the resulting DataFrame in the audi_cars variable.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 9
toggle bottom row

book
Deleting 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.

python
  • 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.

We'll start by examining the DataFrame:

1234567
import pandas as pd countries_data = {'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(countries_data) print(countries)
copy

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

12345678
import pandas countries_data = {'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(countries_data) countries = countries.drop(columns = ['continent'],axis=1) print(countries)
copy
Tehtävä

Swipe to start coding

You are given a DataFrame named audi_cars.

  • Remove the 'capital' column and save the resulting DataFrame in the audi_cars variable.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 9
Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt