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

get count of unique values in column pandas

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

print (df)
domain
'facebook.com'    1
'google.com'      1
'twitter.com'     2
'vk.com'          3
Name: ID, dtype: int64
Comment

how to count unique values in a column dataframe in python

dataframe.column.nunique()
Comment

finding the Unique values in data

##finding the Unique values in data ie: Age

df['Age'].unique()
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

dataframe number of unique rows

1
# get the unique values (rows) by retaining last row
2
df.drop_duplicates(keep='last')
Comment

pandas get number unique values in column

df["Your_Column"].nunique()
Comment

PREVIOUS NEXT
Code Example
Python :: loop through python object 
Python :: how to add vertical line on subplot in matplotlib 
Python :: pyautogui press 
Python :: pandas change to numeric 
Python :: python how to create dict from dataframe based on 2 columns 
Python :: access sqlite db python 
Python :: python proxy scraper 
Python :: pandas distinct 
Python :: python requests response get text 
Python :: pandas write to excel 
Python :: how to make a venv python 
Python :: how to create string in python 
Python :: python check if 3 values are equal 
Python :: axios django 
Python :: find all files containing a string in python with glob module 
Python :: pandas delete column by name 
Python :: plot size 
Python :: object to int and float conversion pandas 
Python :: change dataframe value by index 
Python :: pip install streamlit 
Python :: read from text file and append in list 
Python :: python how to keep turtle window open 
Python :: how to add rows to empty dataframe 
Python :: split column by comma pandas 
Python :: press key on python 
Python :: find max length in string in pandas dataframe 
Python :: Get all the numerical column from the dataframe using python 
Python :: raise exception in python 
Python :: datetime strptime format 
Python :: how to import sin and cos in python 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =