Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to count number of unique values in a column python

pd.value_counts(df.Account_Type)

Gold        3
Platinum    1
Name: Account_Type, dtype: int64
Comment

python count number of unique elements in a list

# Basic syntax:
len(set(my_list))
# By definition, sets only contain unique elements, so when the list
# is converted to a set all duplicates are removed. 

# Example usage:
my_list = ['so', 'so', 'so', 'many', 'duplicated', 'words']
len(set(my_list))
--> 4

# Note, list(set(my_list)) is a useful way to return a list containing
#	only the unique elements in my_list
Comment

Count unique values Pandas

df = df.groupby('domain')['ID'].nunique()
Comment

count unique values pandas

df['hID'].nunique()
5
Comment

count unique elements in list python

from collections import Counter

words = ['a', 'b', 'c', 'a']

Counter(words).keys() # equals to list(set(words))
Counter(words).values() # counts the elements' frequency
Comment

count unique values in python

words = ['a', 'b', 'c', 'a']
unique_words = set(words)             # == set(['a', 'b', 'c'])
unique_word_count = len(unique_words) # == 3
Comment

counting unique values python

df.loc[df['mID']=='A','hID'].agg(['nunique','count','size'])
Comment

python count unique values in list

len(set(["word1", "word1", "word2", "word3"]))
# set is like a list but it removes duplicates
# len counts the number of things inside the set
Comment

PREVIOUS NEXT
Code Example
Python :: how to search for an item in a list in python 
Python :: how can I print all items in a tuple, separated by commas? 
Python :: pipeline model coefficients 
Python :: separate each characters by commas into a single characters separated by commas 
Python :: df shape 
Python :: 151 - Power Crisis solution in python 
Python :: sum of fraction numbers in python 
Python :: python mongodb docker 
Python :: python string not contains 
Python :: unpacking tuples in python 
Python :: Python use number twice without variable 
Python :: @methodclass in python 
Python :: python find all occurrence in string 
Python :: variable bound to a set python 
Python :: start ipython with any version 
Python :: midpoint circle drawing algorithm 
Python :: new print on the same line substitution python 3 
Python :: how to query DNS records using python 
Python :: if statement python 
Python :: pandas.core.indexes into list 
Python :: float error python 
Python :: install tabula 
Python :: convert int to ascii python 
Python :: *kwargs 
Python :: how to get the end of a item in a python array 
Python :: How to Join list element into a string in python 
Python :: Python Program to Shuffle Deck of Cards 
Python :: python matplotlib pyplot set axis equals 
Python :: networkx node attribute from a dataframe 
Python :: django request.data example 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =