generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plots.py
34 lines (29 loc) · 1.46 KB
/
plots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pandas as pd
from utilities import *
if not (OUTPUT_DIR / "figures").exists():
Path.mkdir(OUTPUT_DIR / "figures")
breakdowns=[
"age_band",
"sex",
"imdQ5",
"region",
"ethnicity",
"nhome",
"learning_disability",
"care_home_type"
]
med_review_type=["smr", "mr"]
for med_review in med_review_type:
df = pd.read_csv(OUTPUT_DIR / f"joined/measure_{med_review}_population_rate.csv", parse_dates=["date"])
plot_measures(df, filename=f"{med_review}_population_rate", title="", column_to_plot="value", y_label="Rate")
for breakdownby in breakdowns:
df = pd.read_csv(OUTPUT_DIR / f"joined/measure_{med_review}_{breakdownby}_rate.csv", parse_dates=["date"])
df[breakdownby] = df[breakdownby].fillna('missing')
if (breakdownby == "care_home_type"):
df=binary_care_home_status(df, f'had_{med_review}', 'population')
convert_binary(df, 'care_home_type', 'Record of positive care home status', 'No record of positive care home status')
if (breakdownby == "learning_disability"):
convert_binary(df, 'learning_disability', 'Record of learning disability', 'No record of learning disability')
if (breakdownby == "nhome"):
convert_binary(df, 'nhome', 'Record of individual living at a nursing home', 'No record of individual living at a nursing home')
plot_measures(df, filename=f"{med_review}_{breakdownby}_rate", title="", column_to_plot="value", y_label="Rate", category=breakdownby)