daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import matplotlib.pyplot as plt
  2. import seaborn as sns
  3. import pandas as pd
  4. import statsmodels.api as sm
  5. import numpy as np
  6.  
  7. da = pd.read_csv("nhanes_2015_2016.csv")
  8.  
  9. da["DMDMARTL"] = da.DMDMARTL.fillna("Missing")
  10. da["DMDMARTLdescript"] = da.DMDMARTL.replace({1: "Married", 2: "Widowed", 3: "Divorced", 4: "Separated", 5: "Never married",
  11.                              6: "Living with partner",       77: "Refused", 99: "Don't know"})
  12.  
  13. da["RIAGENDRx"] = da.RIAGENDR.replace({1: "Male", 2: "Female"})
  14.  
  15. da["agegrp"] = pd.cut(da.RIDAGEYR, [10, 20, 30, 40, 50, 60, 70, 80])
  16.    
  17. y = "prop"
  18. dx = da.loc[~da.RIAGENDRx.isin(["Male"]), :]
  19. plt.figure(figsize=(12, 5))
  20. prop_df = (dx["agegrp"]
  21.        .groupby(dx["DMDMARTLdescript"])
  22.        .value_counts(normalize=True)
  23.        .rename(y)
  24.        .reset_index())
  25. sns.barplot(x="agegrp", y=y, hue="DMDMARTLdescript", data=prop_df)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top