Course Content
Introduction to pandas [track]
Introduction to pandas [track]
Unique Observations
You can get unique values of particular column by applying the .unique()
method. Note, that this is Series
method, so it works only for one column of DataFrame. For example, you can get all the cars' fuel types.
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Unique fuel types print(df.fuelType.unique())
Also you can get the total number of unique values within specific column by applying .nunique()
method to the column.
# Importing library import pandas as pd # Reading csv file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/67798cef-5e7c-4fbc-af7d-ae96b4443c0a/audi.csv') # Number of unique engine sizes print(df.engineSize.nunique())
Thanks for your feedback!