Get Unique Values in Pandas Column ๐ผ
Learn how to find distinct values in a pandas DataFrame column with simple code examples.

DataDaft
9.2K views โข Oct 30, 2020

About this video
โ Code Available Below! โ
This video shows how to check the unique or distinct values in a column of a pandas data frame. This can be useful to get an idea of the number of variety of values in a given column. The video also shows a method for checking all the combinations of values in two or more columns.
If you find this video useful, like, share and subscribe to support the channel!
โบ Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
import pandas as pd
import statsmodels.api as sm #(To access mtcars dataset)
mtcars = sm.datasets.get_rdataset("mtcars", "datasets", cache=True).data
mtcars.head()
# Get unique entries of a column with series.unique()
mtcars["cyl"].unique()
# Get unique entries across multiple columns
mtcars_subset = mtcars[["cyl", "gear"]]
mtcars_subset.drop_duplicates().reset_index(drop=True)
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large ๏ผ and ๏ผ symbols in place of the standard sized ones. .
โญ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while youโre typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only
This video shows how to check the unique or distinct values in a column of a pandas data frame. This can be useful to get an idea of the number of variety of values in a given column. The video also shows a method for checking all the combinations of values in two or more columns.
If you find this video useful, like, share and subscribe to support the channel!
โบ Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
import pandas as pd
import statsmodels.api as sm #(To access mtcars dataset)
mtcars = sm.datasets.get_rdataset("mtcars", "datasets", cache=True).data
mtcars.head()
# Get unique entries of a column with series.unique()
mtcars["cyl"].unique()
# Get unique entries across multiple columns
mtcars_subset = mtcars[["cyl", "gear"]]
mtcars_subset.drop_duplicates().reset_index(drop=True)
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large ๏ผ and ๏ผ symbols in place of the standard sized ones. .
โญ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while youโre typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only
Tags and Topics
Browse our collection to discover more content in these categories.
Video Information
Views
9.2K
Likes
128
Duration
1:44
Published
Oct 30, 2020
User Reviews
4.5
(1) Related Trending Topics
LIVE TRENDSRelated trending topics. Click any trend to explore more videos.