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

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

pandas unique values to list

df.groupby('param')['column'].nunique().sort_values(ascending=False).unique().tolist()
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

get unique values from a list

mylist = ['nowplaying', 'PBS', 'PBS', 'nowplaying', 'job', 'debate', 'thenandnow']
myset = set(mylist)
print(myset)
mynewlist = list(myset)
#['nowplaying', 'PBS', 'job', 'debate', 'thenandnow']
Comment

PREVIOUS NEXT
Code Example
Python :: get page source code selenium python 
Python :: blender python set object to active by name 
Python :: python removing from string 
Python :: erode dilate opencv python 
Python :: download pdf from url python 
Python :: python exception element not found 
Python :: Installing python cryptography 
Python :: pandas rename index 
Python :: how to check if column has na python 
Python :: random letter generator python 
Python :: remove extension from filename python 
Python :: pandas plotly backend 
Python :: how to get size of folder python 
Python :: check numpy version 
Python :: python read csv line by line 
Python :: how to set the screen brightness using python 
Python :: python program to keep your computer awake 
Python :: pandas append csv files a+ 
Python :: pandas percent change 
Python :: python convert number to string with leading zeros 
Python :: python change working directory to file directory 
Python :: python discord bot join voice channel 
Python :: python get majority of list 
Python :: ctypes run as administrator 
Python :: check gpu in tensorflow 
Python :: count missing values by column in pandas 
Python :: user agent for python 
Python :: python time using timeit module 
Python :: selenium-screenshot python 
Python :: dns request scapy 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =