CardiovascularDisease/CVD/data_visualizer.py
def draw_cat_plot(df: pd.DataFrame, id_var: str, cat_feats: list, *, output_filename: str =None):
    """
    Draw plot showing value counts of categorical features.

    :parameter dframe: pandas dataframe containing the feature `id_var` and all of the features in `cat_feats`.
                       Note: this implementation does not check that all of the relevant features are in `dframe`.
    :parameter id_var: Feature name (string) with respect to which panels of the categorical plot
                       are made. For instance, for a binary feature, the plot will
                       have two panels showing the respective counts of categorical features.
    :parameter cat_feats: list of strings of categorical features to plot.
    :parameter output_filename: if the plot is to be saved, this is its name.
                                (default=None, i.e., plot is not saved)

    :return: Seaborn figure object.
    """

    # Create DataFrame for cat plot using `pd.melt` using just the values from categorical features
    df_cat = pd.melt(df, id_vars=id_var, value_vars=cat_feats)

    # Draw the catplot
    fig = sns.catplot(x="variable", hue="value", col=id_var, data=df_cat, 
                      kind="count")
    fig.set_xlabels('')
    fig.set_xticklabels(rotation=90)
    fig.savefig(output_filename) if output_filename is not None else True

    return fig

    Draw plot showing value counts of categorical features.

    :parameter dframe: pandas dataframe containing the feature `id_var` and all of the features in `cat_feats`.
                       Note: this implementation does not check that all of the relevant features are in `dframe`.
    :parameter id_var: Feature name (string) with respect to which panels of the categorical plot
                       are made. For instance, for a binary feature, the plot will
                       have two panels showing the respective counts of categorical features.
    :parameter cat_feats: list of strings of categorical features to plot.
    :parameter output_filename: if the plot is to be saved, this is its name.
                                (default=None, i.e., plot is not saved)

    :return: Seaborn figure object.
    
Draw plot showing value counts of categorical features.
Draw plot showing value counts of categorical features .
def draw_cat_plot(df: pd.DataFrame, id_var: str, cat_feats: list, *, output_filename: str =None):
    df_cat = pd.melt(df, id_vars=id_var, value_vars=cat_feats)
    fig = sns.catplot(x="variable", hue="value", col=id_var, data=df_cat, 
                      kind="count")
    fig.set_xlabels('')
    fig.set_xticklabels(rotation=90)
    fig.savefig(output_filename) if output_filename is not None else True
    return fig
def draw_cat_plot ( df : pd . DataFrame , id_var : str , cat_feats : list , * , output_filename : str = None ) : df_cat = pd . melt ( df , id_vars = id_var , value_vars = cat_feats ) fig = sns . catplot ( x = "variable" , hue = "value" , col = id_var , data = df_cat , kind = "count" ) fig . set_xlabels ( '' ) fig . set_xticklabels ( rotation = 90 ) fig . savefig ( output_filename ) if output_filename is not None else True return fig
Draw plot showing value counts of categorical features.
Draw plot showing value counts of categorical features .
"""
    Draw plot showing value counts of categorical features.

    :parameter dframe: pandas dataframe containing the feature `id_var` and all of the features in `cat_feats`.
                       Note: this implementation does not check that all of the relevant features are in `dframe`.
    :parameter id_var: Feature name (string) with respect to which panels of the categorical plot
                       are made. For instance, for a binary feature, the plot will
                       have two panels showing the respective counts of categorical features.
    :parameter cat_feats: list of strings of categorical features to plot.
    :parameter output_filename: if the plot is to be saved, this is its name.
                                (default=None, i.e., plot is not saved)

    :return: Seaborn figure object.
    """ # Create DataFrame for cat plot using `pd.melt` using just the values from categorical features # Draw the catplot
Seaborn figure object.
Seaborn figure object .
df
pd.DataFrame
id_var
str
Feature name (string) with respect to which panels of the categorical plot
are made. For instance, for a binary feature, the plot will
have two panels showing the respective counts of categorical features.
Feature name ( string ) with respect to which panels of the categorical plot are made . For instance for a binary feature the plot will have two panels showing the respective counts of categorical features .
cat_feats
list
list of strings of categorical features to plot.
list of strings of categorical features to plot .
output_filename
str
if the plot is to be saved, this is its name.
(default=None, i.e., plot is not saved)
if the plot is to be saved this is its name . ( default = None i . e . plot is not saved )
dframe
pandas dataframe containing the feature `id_var` and all of the features in `cat_feats`.
Note: this implementation does not check that all of the relevant features are in `dframe`.
pandas dataframe containing the feature ` id_var ` and all of the features in ` cat_feats ` . Note : this implementation does not check that all of the relevant features are in ` dframe ` .