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

values of unique from dataframe with count

data = df.groupby('ColumnName')['IDColumnName'].nunique()
print(data)
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

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 variable 
Python :: convert timedelta to days 
Python :: file manage py line 17 from exc django 
Python :: python trim whitespace from end of string 
Python :: python strip 
Python :: pip uninstalled itself 
Python :: python cli click 
Python :: how to append a dataframe to another dataframe in pandas 
Python :: turn characters to alpgabetic numper python 
Python :: if else in list comprehension 
Python :: python numpy matrix to list 
Python :: how to check if there is a word in a string in python 
Python :: easy frequency analysis python 
Python :: python pillow convert jpg to png 
Python :: php datatables serverside 
Python :: sklearn predict threshold 
Python :: factors for negative number python 
Python :: join to dataframes pandas 
Python :: map example in python 
Python :: get user django 
Python :: pandas drop duplicate keep last 
Python :: how to log errors while debug is false in django 
Python :: print with no newline 
Python :: using a dictionary in python 
Python :: month name in python 
Python :: python positional argument follows keyword argument 
Python :: python remove empty values from list 
Python :: opencv loop video 
Python :: generate rsa key python 
Python :: python print f 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =