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

pandas unique values to list

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

Get unique values from a Python list

# just turn it into a set and then convert again into a list
res = list(set(lst1)))
 
# now check the lengths of the two lists
print(len(res))
print(len(lst1))
Comment

PREVIOUS NEXT
Code Example
Python :: python pandas column where 
Python :: how to get dictionary input from user in python 
Python :: progress bar python 
Python :: how to count null values in pandas and return as percentage 
Python :: mid point formula 
Python :: python using numpy 
Python :: numpy randint 
Python :: python print with 2 decimals 
Python :: soup findall table 
Python :: image crop in python 
Python :: how to run same function on multiple threads in pyhton 
Python :: matplotlib animate 
Python :: bot ping command 
Python :: startapp django 
Python :: one hot encoding 
Python :: Command errored out with exit status 1: 
Python :: Reading JSON from a File with Python 
Python :: python docx extract image 
Python :: python is inf 
Python :: separating tuple in pandas 
Python :: draw circle pygame 
Python :: django deployment 
Python :: how to get local ip in python 
Python :: python package for misspelled words 
Python :: join() python 
Python :: python download complete web page 
Python :: django get_user_model() function 
Python :: plotting roc curve 
Python :: how to put legend outside pie plot in python 
Python :: tkinter 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =