Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

calculate percentile pandas dataframe

import pandas as pd
import random

A = [ random.randint(0,100) for i in range(10) ]
B = [ random.randint(0,100) for i in range(10) ]

df = pd.DataFrame({ 'field_A': A, 'field_B': B })
df
#    field_A  field_B
# 0       90       72
# 1       63       84
# 2       11       74
# 3       61       66
# 4       78       80
# 5       67       75
# 6       89       47
# 7       12       22
# 8       43        5
# 9       30       64

df.field_A.mean()   # Same as df['field_A'].mean()
# 54.399999999999999

df.field_A.median() 
# 62.0

# You can call `quantile(i)` to get the i'th quantile,
# where `i` should be a fractional number.

df.field_A.quantile(0.1) # 10th percentile
# 11.9

df.field_A.quantile(0.5) # same as median
# 62.0

df.field_A.quantile(0.9) # 90th percentile
# 89.10000000000001
Comment

percent in pandas

sum(df['sex'] == 'man') / len(df)
Comment

calculate percentile pandas dataframe

import pandas as pd
import random

A = [ random.randint(0,100) for i in range(10) ]
B = [ random.randint(0,100) for i in range(10) ]

df = pd.DataFrame({ 'field_A': A, 'field_B': B })
df
#    field_A  field_B
# 0       90       72
# 1       63       84
# 2       11       74
# 3       61       66
# 4       78       80
# 5       67       75
# 6       89       47
# 7       12       22
# 8       43        5
# 9       30       64

df.field_A.mean()   # Same as df['field_A'].mean()
# 54.399999999999999

df.field_A.median() 
# 62.0

# You can call `quantile(i)` to get the i'th quantile,
# where `i` should be a fractional number.

df.field_A.quantile(0.1) # 10th percentile
# 11.9

df.field_A.quantile(0.5) # same as median
# 62.0

df.field_A.quantile(0.9) # 90th percentile
# 89.10000000000001
Comment

percent in pandas

sum(df['sex'] == 'man') / len(df)
Comment

PREVIOUS NEXT
Code Example
Python :: turtle graphics documentation 
Python :: check datatype python 
Python :: python parse int as string 
Python :: super in django manager 
Python :: pandas replace values 
Python :: get index of all element in list python 
Python :: python working with files and dirs 
Python :: latest version of python 
Python :: activate virtual environment 
Python :: python mqtt subscribe code 
Python :: python variable scope 
Python :: anagrams string python 
Python :: scikit learn to identify highly correlated features 
Python :: making ckeditor django responsive 
Python :: Javascript rendering html 
Python :: free download django app for windows 10 
Python :: how to merge two column pandas 
Python :: django create view class 
Python :: pandas remove whitespace 
Python :: Converting Categorical variables in to integers using Dummy 
Python :: python captcha bypass 
Python :: traversing dictionary in python 
Python :: else if python 
Python :: flask socketio usage 
Python :: hist pandas 
Python :: pyqt set focus 
Python :: isolationforest estimators 
Python :: how to use coordinates in python 
Python :: how to append two pandas dataframe 
Python :: x y coordinates in python 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =