How to get unique values in a column in pandas

Spread the love

Problem –

You have a column in a DataFrame and you want to get all the unique values from that column.

Solution –

import pandas as pd

url = "https://raw.githubusercontent.com/bprasad26/lwd/master/data/clothing_store_sales.csv"
df = pd.read_csv(url)
df.head()

Let’s say that you want all the unique values in the Method of Payment column.

df['Method of Payment'].unique()

You can also apply it to a numerical column.

df['Age'].unique()

Rating: 1 out of 5.

Leave a Reply