Skip to content

Instantly share code, notes, and snippets.

@cereniyim
Created April 29, 2020 11:17
Show Gist options
  • Save cereniyim/e0e76901e558930eab0ceda99f3e88f4 to your computer and use it in GitHub Desktop.
Save cereniyim/e0e76901e558930eab0ceda99f3e88f4 to your computer and use it in GitHub Desktop.
plot distirbution of a variable per a categorical variable
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