
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Python Pandas – Find unique values from a single column
To find unique values from a single column, use the unique() method. Let’s say you have Employee Records in your Pandas DataFrame, so the names can get repeated since two employees can have similar names. In that case, if you want unique Employee names, then use the unique() for DataFrame.
At first, import the required library. Here, we have set pd as an alias −
import pandas as pd
At first, create a DataFrame. Here, we have two columns −
dataFrame = pd.DataFrame( { "EmpName": ['John', 'Ted', 'Jacob', 'Scarlett', 'Ami', 'Ted', 'Scarlett'],"Zone": ['North', 'South', 'South', 'East', 'West', 'East', 'North'] } )
Fetch unique Employee Names from the DataFrame column “EmpName” −
dataFrame['EmpName'].unique()
Example
Following is the complete code −
import pandas as pd # Create DataFrame dataFrame = pd.DataFrame( { "EmpName": ['John', 'Ted', 'Jacob', 'Scarlett', 'Ami', 'Ted', 'Scarlett'],"Zone": ['North', 'South', 'South', 'East', 'West', 'East', 'North'] } ) print("DataFrame ...\n",dataFrame) # Fetch unique value from a single column print(f"\nUnique Name of Employees = {dataFrame['EmpName'].unique()}")
Output
This will produce the following output −
DataFrame1 ... EmpName Zone 0 John North 1 Ted South 2 Jacob South 3 Scarlett East 4 Ami West 5 Ted East 6 Scarlett North Unique Name of Employees = ['John' 'Ted' 'Jacob' 'Scarlett' 'Ami']
- Related Articles
- Python Pandas - Get unique values from a column
- Python Pandas – Find unique values from multiple columns
- Python Pandas - Display unique values present in each column
- Python Pandas - Return a Series containing counts of unique values from Index object
- Python – Stacking a single-level column with Pandas stack()?
- Count unique values per groups in Python Pandas
- Python Pandas - Return unique values in the index
- Python Pandas - Return a Series containing counts of unique values from Index object considering NaN values as well
- Python Pandas - Check if the index has unique values
- Get unique values from a list in Python
- Python - Cast datatype of only a single column in a Pandas DataFrame
- Python Program to print unique values from a list
- Select rows from a Pandas DataFrame based on column values
- Python Pandas - Return a Series containing counts of unique values from Index object sorted in Ascending Order
- Python - Remove a column with all null values in Pandas

Advertisements