text_html_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

data_df = pd.read_csv('../input/mushrooms.csv')

data_df['y'] = data_df['class'].map({'p': 1, 'e': 0})
columns = [c for c in data_df.columns if not c in ('class', 'y')]
stats_df = []
single_val_c = {}
for i, c in enumerate(columns):
    if data_df[c].nunique() == 1:
        single_val_c[c] = data_df[c].unique()[0]
        continue
    gb = data_df.groupby(c)
    m = gb['y'].mean()
    s = gb.size()
    s = s.values / s.sum()
    df = pd.DataFrame(columns=['col', 'val', 'mean_y', 'persent'], index=range(len(m)))
    df['col'] = c
    df['val'] = m.index.values
    df['mean_y'] = m.values
    df['persent'] = s
    stats_df.append(df)
stats_df = pd.concat(stats_df, axis=0)

stats_df.head()