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

percent in pandas

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

calculate values in a certain percentile pandas

# Calculate the minimum number of votes required to be in the chart, m
m = metadata['vote_count'].quantile(0.90)
print(m)
Comment

PREVIOUS NEXT
Code Example
Python :: numpy save multiple arrays 
Python :: count unique elements in list python 
Python :: tensorflow adam 
Python :: newsapi in python 
Python :: SystemError: tile cannot extend outside image 
Python :: kill python process with bash 
Python :: python user input 
Python :: how to create enter pressed for qlineedit in pyqt5 
Python :: append value to numpy array 
Python :: fill nan values with mean 
Python :: how to run .exe from python 
Python :: get the last element from the list 
Python :: python byte string 
Python :: merge dataframe pandas 
Python :: input numpy array 
Python :: random number generator in python 
Python :: moving averages python 
Python :: openai python 
Python :: multiple bar graph in python 
Python :: python hide print output 
Python :: create virtual environments python 
Python :: keras declare functional model 
Python :: bitcoin wallet python 
Python :: install coverage python 
Python :: django queryset first element 
Python :: train test split sklearn 
Python :: python get architecture 
Python :: how to change index date format pandas 
Python :: custom jupyter notebook 
Python :: Converting Dataframe from the multi-dimensional list 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =