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

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 :: display max rows pandas 
Python :: dataframe to list 
Python :: How to update python using anaconda/conda 
Python :: .astype datetime 
Python :: how to add images in hml while using flask 
Python :: plot categorical data matplotlib 
Python :: how to convert a am pm string to 24 hrs time python 
Python :: converting a csv into python list 
Python :: plotly plot size 
Python :: how to apply logarithm in pandas dataframe 
Python :: How do you sum consecutive numbers in Python? 
Python :: python number to array of digits 
Python :: How to use tqdm with pandas apply 
Python :: xgboost feature importance 
Python :: print specific part in bold or colours and end. 
Python :: how to print char of element in list of pytohn 
Python :: import decisiontreeclassifier 
Python :: image delete in django from the folder 
Python :: kivymd simple button 
Python :: xpath beautifulsoup 
Python :: tkinter start maximized 
Python :: simplify fractions python 
Python :: remove rows if not matching with value in df 
Python :: python cube turtle 
Python :: python remove empty folders 
Python :: pyqt5 wait cursor 
Python :: python discord discord.py disable remove help command 
Python :: python parse args 
Python :: python matplotlib inline 
Python :: rolling average df 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =