Created
May 28, 2021 14:34
-
-
Save patrickbrus/eb8dbcf105913a5810de7164d7b56ecf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a histplot of age with hue stroke to check influence of age on class stroke | |
sns.histplot(data=df, x="age", hue="stroke", multiple="stack") | |
# create histplot of gender to check if there is any influence of gender on class stroke | |
sns.histplot(data=df, x="gender", hue="stroke", multiple="stack") | |
# create histplot of smoking_satus and check influence on class stroke | |
sns.histplot(data=df, x="smoking_status", hue="stroke", multiple="stack") | |
# here: can be interesting to also print the percentage of stroke patients of each category | |
count_per_group_smoked_status = df.groupby("smoking_status").count()["stroke"] | |
count_stroke_per_group = df.loc[df["stroke"] == 1].groupby("smoking_status").count()["stroke"] | |
groups = count_per_group_smoked_status.index.to_list() | |
for idx, (count, group_count) in enumerate(zip(count_stroke_per_group, count_per_group_smoked_status)): | |
print(f"Percentage of stroke cases in group {groups[idx]}: {100 * count / group_count}%") | |
# create histplot of ever_married and check influence on class stroke | |
sns.histplot(data=df, x="ever_married", hue="stroke", multiple="stack") | |
# again: check percentage of stroke patients being married and not being married | |
# could be interesting for arguing for or against a wedding ;) | |
# get percentage of strokes per category | |
count_per_group_married_status = df.groupby("ever_married").count()["stroke"] | |
count_stroke_per_group = df.loc[df["stroke"] == 1].groupby("ever_married").count()["stroke"] | |
groups = count_per_group_married_status.index.to_list() | |
for idx, (count, group_count) in enumerate(zip(count_stroke_per_group, count_per_group_married_status)): | |
print(f"Percentage of stroke cases in group {groups[idx]}: {100 * count / group_count}%") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment