Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas select percentile

In [48]: cols = list('abc')

In [49]: df = DataFrame(randn(10, len(cols)), columns=cols)

In [50]: df.a.quantile(0.95)
Out[50]: 1.5776961953820687
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

PREVIOUS NEXT
Code Example
Python :: return the count of a given substring from a string python 
Python :: matplotlib log2 xaxis 
Python :: python paramiko check ssh connection 
Python :: remove all files in a directory mac 
Python :: check column type pandas 
Python :: how to fill na python 
Python :: opencv flip image 
Python :: typage in python 
Python :: how to check sklearn version 
Python :: create random dataframe pandas 
Python :: rotate image pyqt5 
Python :: list map lambda python 
Python :: Solving environment: failed with initial frozen solve. retrying with flexible solve 
Python :: static and media files in django 
Python :: pandas columns add prefix 
Python :: check empty dataframe 
Python :: hcf program in python 
Python :: find geomean of a df 
Python :: asyncio wirte to text python 
Python :: what is the meaning of illiteral with base 10 
Python :: draw pixel by pixel python 
Python :: python program for geometric progression 
Python :: matplotlib change bar color under threshold 
Python :: python make a shop menu 
Python :: apolatrix 
Python :: media url django 
Python :: replace space with _ in pandas 
Python :: pandas dataframe creation column names 
Python :: pytube search feature 
Python :: python strftime microseconds 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =