Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get list of unique values in pandas column

a = df['column name'].unique() #returns a list of unique values
Comment

dataframe unique values in each column

for col in df:
    print(df[col].unique())
Comment

count unique values in pandas column

df['column_name'].value_counts()
Comment

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())
Comment

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())
Comment

how to get unique value of all columns in pandas

print(df.apply(lambda col: col.unique()))
Comment

Getting unique values in a column

# 10. Getting unique names of values in a column
df['Airline'].unique()
Comment

dataframe python unique values rows

# get the unique values (rows)
df.drop_duplicates()
Comment

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())
Comment

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
Comment

pandas get number unique values in column

df["Your_Column"].nunique()
Comment

PREVIOUS NEXT
Code Example
Python :: how to find the last item of a list 
Python :: json python 
Python :: python coding questions and answers 
Python :: split a string by comma in python 
Python :: how to make a program that identifies positives and negatives in python 
Python :: extract data from json file python 
Python :: Write a Python program to get the Python version you are using. 
Python :: python reversed range 
Python :: python docstring example 
Python :: numpy add new column 
Python :: py env 
Python :: get columns by type pandas 
Python :: check if a the time is 24 hours older python 
Python :: python iterate through string in reverse 
Python :: python list only files not directories 
Python :: python how to count number of true 
Python :: split column by comma pandas 
Python :: imread real color cv2 
Python :: change to first letter capital list python 
Python :: knowing the sum null values in a specific row in pandas dataframe 
Python :: python timer decorator 
Python :: E: Unable to locate package python-gobject 
Python :: find character in python 
Python :: how to clear a list in python 
Python :: install SocketIO flask 
Python :: Chi-Squared test in python 
Python :: pandas drop row from a list of value 
Python :: python matplt 
Python :: ad background image with tkinter 
Python :: ordereddict 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =