Calculate Percentile Pandas Dataframe Code Example

Snippet 1
  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 

Similar Snippets


Combine Two Dataframe In Pandas Code Example - pandas

Pandas Dataframe Froms String Code Example - pandas

Append New Data On Pandas Dataframe Code Example - pandas

Getting Dummies And Input Them To Pandas Dataframe Code Example - pandas

How To Set Pandas Dataframe As Global Code Example - pandas

Dictionary To A Dataframe Pandas Arrays Must All Be Same Length Code Example - pandas

Pandas Iterrows Code Example - pandas

Slicing In Pandas Code Example - pandas

Pandas Count Rows With Value Code Example - pandas

Add An Index Column Pandas Code Example - pandas

Pandas Ttable With Sum Totals Code Example - pandas

Remove 1st Column Pandas Code Example - pandas

Str_Count On Pandas Series Code Example - pandas

Convert Pandas Data Frame To Latex File Code Example - pandas

How To Drop Columns In Pandas Code Example - pandas

Pandas Select All Columns Except One Code Example - pandas

How To Change Column Name In Pandas Code Example - pandas

Index Max Pandas Code Example - pandas

Rename Row Pandas Code Example - pandas

Pandas Cumulative Sum Column Code Example - pandas

Creating A Pandas Df Code Example - pandas

Pandas Read From Website Code Example - pandas

Pandas Show Top 10 Rows Code Example - pandas

How To Merge Two Column Pandas Code Example - pandas

Pandas Merge Two Columns From Different Dataframes Code Example - pandas

Pandas Read Excel With Two Headers Code Example - pandas

Pandas Frame Convert String Code Example - pandas

Onehot Encode List Of Columns Pandas Code Example - pandas

Reshape Wide To Long In Pandas Code Example - pandas