Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Unique Values | Analyzing the Data
Pandas First Steps
course content

Course Content

Pandas First Steps

Pandas First Steps

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

Unique Values

Data often gets duplicated in DataFrames. For instance, in our countries DataFrame, the continent column has repeated entries. There's a function that retrieves an array of distinct values from a specific DataFrame column. Let's revisit this DataFrame.

1234567
import pandas as pd 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 = pd.DataFrame(dataset) print(countries)
copy

Now, let's apply the unique() method to the 'continent' and 'country' columns.

12345678910
import pandas as pd 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 = pd.DataFrame(dataset) unique_countries = countries['country'].unique() unique_continents = countries['continent'].unique() print(unique_countries) print(unique_continents)
copy

Task

Given the audi_cars DataFrame, please identify all distinct values in the 'year' and 'fueltype' columns.

Task

Given the audi_cars DataFrame, please identify all distinct values in the 'year' and 'fueltype' columns.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 3. Chapter 16
toggle bottom row

Unique Values

Data often gets duplicated in DataFrames. For instance, in our countries DataFrame, the continent column has repeated entries. There's a function that retrieves an array of distinct values from a specific DataFrame column. Let's revisit this DataFrame.

1234567
import pandas as pd 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 = pd.DataFrame(dataset) print(countries)
copy

Now, let's apply the unique() method to the 'continent' and 'country' columns.

12345678910
import pandas as pd 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 = pd.DataFrame(dataset) unique_countries = countries['country'].unique() unique_continents = countries['continent'].unique() print(unique_countries) print(unique_continents)
copy

Task

Given the audi_cars DataFrame, please identify all distinct values in the 'year' and 'fueltype' columns.

Task

Given the audi_cars DataFrame, please identify all distinct values in the 'year' and 'fueltype' columns.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 3. Chapter 16
toggle bottom row

Unique Values

Data often gets duplicated in DataFrames. For instance, in our countries DataFrame, the continent column has repeated entries. There's a function that retrieves an array of distinct values from a specific DataFrame column. Let's revisit this DataFrame.

1234567
import pandas as pd 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 = pd.DataFrame(dataset) print(countries)
copy

Now, let's apply the unique() method to the 'continent' and 'country' columns.

12345678910
import pandas as pd 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 = pd.DataFrame(dataset) unique_countries = countries['country'].unique() unique_continents = countries['continent'].unique() print(unique_countries) print(unique_continents)
copy

Task

Given the audi_cars DataFrame, please identify all distinct values in the 'year' and 'fueltype' columns.

Task

Given the audi_cars DataFrame, please identify all distinct values in the 'year' and 'fueltype' columns.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Data often gets duplicated in DataFrames. For instance, in our countries DataFrame, the continent column has repeated entries. There's a function that retrieves an array of distinct values from a specific DataFrame column. Let's revisit this DataFrame.

1234567
import pandas as pd 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 = pd.DataFrame(dataset) print(countries)
copy

Now, let's apply the unique() method to the 'continent' and 'country' columns.

12345678910
import pandas as pd 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 = pd.DataFrame(dataset) unique_countries = countries['country'].unique() unique_continents = countries['continent'].unique() print(unique_countries) print(unique_continents)
copy

Task

Given the audi_cars DataFrame, please identify all distinct values in the 'year' and 'fueltype' columns.

Switch to desktop for real-world practiceContinue from where you are using one of the options below
Section 3. Chapter 16
Switch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt