Let’s discuss how to get unique values from a column in Pandas DataFrame.
Create a simple dataframe with dictionary of lists, say columns name are A, B, C, D, E with duplicate elements.

Now, let’s get the unique values of a column in this dataframe.
Example #1: Get the unique values of ‘B’ column
# Import pandas package import pandas as pd # create a dictionary with five fields each data = { 'A':['A1', 'A2', 'A3', 'A4', 'A5'], 'B':['B1', 'B2', 'B3', 'B4', 'B4'], 'C':['C1', 'C2', 'C3', 'C3', 'C3'], 'D':['D1', 'D2', 'D2', 'D2', 'D2'], 'E':['E1', 'E1', 'E1', 'E1', 'E1'] } # Convert the dictionary into DataFrame df = pd.DataFrame(data) # Get the unique values of 'B' column df.B.unique() |
Output:
![]()
Example #2: Get the unique values of ‘E’ column
# Import pandas package import pandas as pd # create a dictionary with five fields each data = { 'A':['A1', 'A2', 'A3', 'A4', 'A5'], 'B':['B1', 'B2', 'B3', 'B4', 'B4'], 'C':['C1', 'C2', 'C3', 'C3', 'C3'], 'D':['D1', 'D2', 'D2', 'D2', 'D2'], 'E':['E1', 'E1', 'E1', 'E1', 'E1'] } # Convert the dictionary into DataFrame df = pd.DataFrame(data) # Get the unique values of 'E' column df.E.unique() |
Output:
![]()
Example #3: Get number of unique values in a column
# Import pandas package import pandas as pd # create a dictionary with five fields each data = { 'A':['A1', 'A2', 'A3', 'A4', 'A5'], 'B':['B1', 'B2', 'B3', 'B4', 'B4'], 'C':['C1', 'C2', 'C3', 'C3', 'C3'], 'D':['D1', 'D2', 'D2', 'D2', 'D2'], 'E':['E1', 'E1', 'E1', 'E1', 'E1'] } # Convert the dictionary into DataFrame df = pd.DataFrame(data) # Get number of unique values in column 'C' df.C.nunique(dropna = True) |
Output:
![]()
Recommended Posts:
- Getting Unique values from a column in Pandas dataframe
- Get column index from column name of a given Pandas DataFrame
- Get n-smallest values from a particular column in Pandas DataFrame
- Get n-largest values from a particular column in Pandas DataFrame
- Get a list of a particular column values of a Pandas DataFrame
- Create a Pandas DataFrame from a Numpy array and specify the index column and column headers
- Convert given Pandas series into a dataframe with its index as another column on the dataframe
- Python - Extract ith column values from jth column values
- How to Concatenate Column Values in Pandas DataFrame?
- Replace all the NaN values with Zero's in a column of a Pandas dataframe
- How to Count Distinct Values of a Pandas Dataframe Column?
- Ways to filter Pandas DataFrame by column values
- Python | Pandas DataFrame.fillna() to replace Null values in dataframe
- How to get column names in Pandas dataframe
- Split a column in Pandas dataframe and get part of it
- Get a list of a specified column of a Pandas DataFrame
- Get list of column headers from a Pandas DataFrame
- Mapping external values to dataframe values in Pandas
- Highlight the negative values red and positive values black in Pandas Dataframe
- Create a DataFrame from a Numpy array and specify the index column and column headers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

