Last active
November 16, 2022 15:58
-
-
Save notha99y/bd5ad4987710f96fc3c31ab5ae3fb000 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 categorical_summarized(dataframe, x=None, y=None, hue=None, palette='Set1', verbose=True): | |
''' | |
Helper function that gives a quick summary of a given column of categorical data | |
Arguments | |
========= | |
dataframe: pandas dataframe | |
x: str. horizontal axis to plot the labels of categorical data, y would be the count | |
y: str. vertical axis to plot the labels of categorical data, x would be the count | |
hue: str. if you want to compare it another variable (usually the target variable) | |
palette: array-like. Colour of the plot | |
Returns | |
======= | |
Quick Stats of the data and also the count plot | |
''' | |
if x == None: | |
column_interested = y | |
else: | |
column_interested = x | |
series = dataframe[column_interested] | |
print(series.describe()) | |
print('mode: ', series.mode()) | |
if verbose: | |
print('='*80) | |
print(series.value_counts()) | |
sns.countplot(x=x, y=y, hue=hue, data=dataframe, palette=palette) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment