Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to get distinct value in a column dataframe in python

df.column.unique()
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

distinct rows in this DataFrame

# distinct rows in this DataFrame

df.distinct().count()
# 2
Comment

pandas distinct

>gapminder['continent'].unique()
array(['Asia', 'Europe', 'Africa', 'Americas', 'Oceania'], dtype=object)
Comment

how to get unique value of all columns in pandas

print(df.apply(lambda col: col.unique()))
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

pandas count distinct values in column

#column name ISSDTM
pd.to_datetime(df.ISSDTM, errors='coerce').dt.year

#result
0    2013
1    2013
2    2009
3    2009
Name: ISSDTM, dtype: int64 
Comment

PREVIOUS NEXT
Code Example
Python :: python print no end of line 
Python :: how to pick a random number in a list python 
Python :: discord embed colors python 
Python :: generate all parameters combination python 
Python :: python strip newline from string 
Python :: distribution plot with curve python 
Python :: how to make a forever loop in python 
Python :: pandas display only certain columns 
Python :: python text fromatting rows 
Python :: not scientific notation python 
Python :: sqlalchemy create engine PostgreSQL 
Python :: python boxplot show mean 
Python :: timed loop python 
Python :: Violin Plots in Seaborn 
Python :: python link to jpg 
Python :: python pynput letter key pressed 
Python :: get current time python 
Python :: how to download excel file from s3 using python 
Python :: python moving average time series 
Python :: pygame.key.get_pressed() 
Python :: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied. 
Python :: how to count in a loop python 
Python :: how to rotate plot in jupyter 
Python :: how to export data from mongodb python 
Python :: drop column dataframe 
Python :: csv reader python skip header 
Python :: delete unnamed coloumns in pandas 
Python :: draw a circle in python turtle 
Python :: dictionary function fromkeys in python 
Python :: tkinter hello world 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =