PYTHON
get list of unique values in pandas column
a = df['column name'].unique() #returns a list of unique values
dataframe unique values in each column
for col in df:
print(df[col].unique())
count unique values in pandas column
df['column_name'].value_counts()
pandas get column values distinct
import pandas as pd
colors = {'color': ['green', 'blue', 'blue', 'red', 'green']}
df = pd.DataFrame.from_dict(colors)
print(df['color'].unique())
How to Find Unique Values in a Column in Pandas
# import pandas library
import pandas as pd
# create pandas DataFrame
df = pd.DataFrame({'fruits': ['orange', 'mango', 'apple', 'grapes', 'orange', 'mango'],
'price': ['40', '80', '30', '40', '30', '80'],
'quantity': ['200', '300', '300', '400', '200', '800']
})
# get the unique value of column fruits
print(df.fruits.unique())
how to get unique value of all columns in pandas
print(df.apply(lambda col: col.unique()))
Getting unique values in a column
# 10. Getting unique names of values in a column
df['Airline'].unique()
dataframe python unique values rows
# get the unique values (rows)
df.drop_duplicates()
Find unique values in all columns in Pandas DataFrame
# import pandas library
import pandas as pd
# create pandas DataFrame
df = pd.DataFrame({'fruits': ['orange', 'mango', 'apple', 'grapes', 'orange', 'mango'],
'price': ['40', '80', '30', '40', '30', '80'],
'quantity': ['200', '300', '300', '400', '200', '800']
})
# get the unique value of all columns
for col in df:
print(df
.unique())
unique rows in dataframe
In [33]: df[df.columns[df.apply(lambda s: len(s.unique()) > 1)]]
Out[33]:
A B
0 0 a
1 1 b
2 2 c
3 3 d
4 4 e
pandas get number unique values in column
df["Your_Column"].nunique()