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 count unique values in a column dataframe in python

dataframe.column.nunique()
Comment

Count unique values Pandas

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

how to count unique values in dataframe df python

#count unique values in each column
df.nunique()

#count unique values in each row
df.nunique(axis=1)
Comment

count unique values pandas

df['hID'].nunique()
5
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

Find and count unique values of a single column 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 count unique values of column fruits
print(df.fruits.value_counts())
Comment

unique values in dataframe column count

df.groupby('mID').agg(['count', 'size', 'nunique']).stack()


             dID  hID  uID
mID                       
A   count      5    5    5
    size       5    5    5
    nunique    3    5    5
B   count      2    2    2
    size       2    2    2
    nunique    2    2    2
C   count      1    1    1
    size       1    1    1
    nunique    1    1    1
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 :: python remove blanks from string 
Python :: count occurrence in array python 
Python :: how to send file in python request 
Python :: python get substring between strings 
Python :: save turtle programming python 
Python :: how to use drf pagination directly 
Python :: closing a file in python 
Python :: numpy divide with exception 
Python :: domain name of my site 
Python :: how to take multiple line inputs in python 
Python :: feature selection python 
Python :: tweepy aut code 
Python :: python planet list 
Python :: python openpyxl cell width 
Python :: pathlib path of current file 
Python :: print random integers py 
Python :: how to set and run flask app on terminal 
Python :: python pip Failed to build cryptography 
Python :: python square a number 
Python :: Groups the DataFrame using the specified columns 
Python :: tkinter button relief options 
Python :: how to add in python 
Python :: Python RegEx Escape – re.escape() 
Python :: math domain error python 
Python :: how to use pip commands in pycharm 
Python :: list comprehension python if else 
Python :: numpy mean 
Python :: how to open a dataset in netcdf4 
Python :: python return number of characters in string 
Python :: what is a framework 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =