Skip to content

Instantly share code, notes, and snippets.

@notha99y
Created December 18, 2018 07:13
Show Gist options
  • Save notha99y/f6a6c4d41a72bc4654c7d2ee81465a2d to your computer and use it in GitHub Desktop.
Save notha99y/f6a6c4d41a72bc4654c7d2ee81465a2d to your computer and use it in GitHub Desktop.
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