Created
April 29, 2020 11:17
-
-
Save cereniyim/e0e76901e558930eab0ceda99f3e88f4 to your computer and use it in GitHub Desktop.
plot distirbution of a variable per a categorical variable
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
def plot_distribution(df, target, column_values, column_name): | |
# funtion to print distribution of a continuous variable | |
# for categorical data | |
for value in column_values: | |
subset = df[df[column_name] == value] | |
g = sns.kdeplot(subset[target], | |
label=value, | |
linewidth=3) | |
# set title, legends and labels | |
plt.ylabel("Density", size=14) | |
plt.xlabel("{}".format(target), size=14) | |
plt.title("Distribution of {} per {}" | |
.format(target, column_name), size=16) | |
return g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment