How to get the unique values of a Dataframe

0 min readPandasData
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

In some cases, you might need to know what are the distinct values of a column in Python.

There exists an easy to do so using pandas DataFrame built-in unique() method.

Here is an example of retrieving the list of distinct products available in a DataFrame containing client orders.

import pandas as pd # We use the pandas library to create a dataframe

df = pd.DataFrame({"product": ["Socks", "Hat", "Cap", "T-Shirt", "Hat", "Socks"], "qty" : [1,1,2,1,3,4]})

print(df["product"].unique()) # We retrieve the product list.

Here you are !

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.