Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import seaborn as sns
- import pandas as pd
- import statsmodels.api as sm
- import numpy as np
- da = pd.read_csv("nhanes_2015_2016.csv")
- da["DMDMARTL"] = da.DMDMARTL.fillna("Missing")
- da["DMDMARTLdescript"] = da.DMDMARTL.replace({1: "Married", 2: "Widowed", 3: "Divorced", 4: "Separated", 5: "Never married",
- 6: "Living with partner", 77: "Refused", 99: "Don't know"})
- da["RIAGENDRx"] = da.RIAGENDR.replace({1: "Male", 2: "Female"})
- da["agegrp"] = pd.cut(da.RIDAGEYR, [10, 20, 30, 40, 50, 60, 70, 80])
- y = "prop"
- dx = da.loc[~da.RIAGENDRx.isin(["Male"]), :]
- plt.figure(figsize=(12, 5))
- prop_df = (dx["agegrp"]
- .groupby(dx["DMDMARTLdescript"])
- .value_counts(normalize=True)
- .rename(y)
- .reset_index())
- sns.barplot(x="agegrp", y=y, hue="DMDMARTLdescript", data=prop_df)
Add Comment
Please, Sign In to add comment