Created
December 18, 2018 07:13
-
-
Save notha99y/f6a6c4d41a72bc4654c7d2ee81465a2d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 quantitative_summarized(dataframe, x=None, y=None, hue=None, palette='Set1', ax=None, verbose=True, swarm=False): | |
''' | |
Helper function that gives a quick summary of quantattive data | |
Arguments | |
========= | |
dataframe: pandas dataframe | |
x: str. horizontal axis to plot the labels of categorical data (usually the target variable) | |
y: str. vertical axis to plot the quantitative data | |
hue: str. if you want to compare it another categorical variable (usually the target variable if x is another variable) | |
palette: array-like. Colour of the plot | |
swarm: if swarm is set to True, a swarm plot would be overlayed | |
Returns | |
======= | |
Quick Stats of the data and also the box plot of the distribution | |
''' | |
series = dataframe[y] | |
print(series.describe()) | |
print('mode: ', series.mode()) | |
if verbose: | |
print('='*80) | |
print(series.value_counts()) | |
sns.boxplot(x=x, y=y, hue=hue, data=dataframe, palette=palette, ax=ax) | |
if swarm: | |
sns.swarmplot(x=x, y=y, hue=hue, data=dataframe, | |
palette=palette, ax=ax) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment