Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- da = pd.read_csv("nhanes_2015_2016.csv")
- x = da.BMXWT.dropna() # Extract all non-missing values of BMXWT into a variable called 'x'
- print(x.mean()) # Pandas method
- print(np.mean(x)) # Numpy function
- print(x.median())
- print(np.percentile(x, 50)) # 50th percentile, same as the median
- print(np.percentile(x, 75)) # 75th percentile
- print(x.quantile(0.75)) # Pandas method for quantiles, equivalent to 75th percentile
- # Considering only the systolic condition, we can calculate the proprotion of the NHANES sample who would be considered to have pre-hypertension.
- np.mean((da.BPXSY1 >= 120) & (da.BPXSY2 <= 139)) # "&" means "and"
- np.mean((da.BPXDI1 >= 80) & (da.BPXDI2 <= 89))
- # or
- a = (da.BPXSY1 >= 120) & (da.BPXSY2 <= 139)
- b = (da.BPXDI1 >= 80) & (da.BPXDI2 <= 89)
- print(np.mean(a | b)) # "|" means "or"
Add Comment
Please, Sign In to add comment