Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

how to count unique values in a column dataframe in python

dataframe.column.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

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

python - subset dataframe based on unique value of a clumn

# Keep first duplicate value
my_df = my_df.drop_duplicates(subset=['my_var'])

# Keep last duplicate value
my_df = my_df.drop_duplicates(subset=['my_var'], keep='last')

# Remove all duplicate values
my_df = my_df.drop_duplicates(subset=['my_var'], keep=False)
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 :: python encrypt password 
Python :: confusion matrix from two columns pandas dataframe 
Python :: df order by 
Python :: yesno django 
Python :: plt.savefig without showing 
Python :: check if numpy array is 1d 
Python :: how to convert a list into string with  
Python :: df change column names 
Python :: equivalent of setInterval python 
Python :: create a dataframe with series 
Python :: pyqt5 qtwebenginewidgets not found 
Python :: python scratch cloud variabelen 
Python :: how to change dtype object to int 
Python :: igraph adjacency matrix python 
Python :: is root node an internal node 
Python :: change tick labelsize matplotlib 
Python :: web scraping linkedin profiles python jupyter 
Python :: how to find exact distance 
Python :: add empty column to dataframe pandas 
Python :: delete row from dataframe python 
Python :: jinja len is undefined 
Python :: likeliness python 
Python :: remove warnings from jupter notebook 
Python :: take two numbers as inout in single line in python 
Python :: discord.py owner only commands 
Python :: vsc python close all functions 
Python :: seconds in a month 
Python :: wtform custom validator example 
Python :: cv2.GaussianBlur() 
Python :: leap year algorithm 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =