text_plain_output_1.png
import pandas as pd

import plotly.graph_objs as go

import plotly.offline as pyo

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

data_df['y'] = data_df['class'].map({'p': 1, 'e': 0})
feature_columns = [c for c in data_df.columns if not c in ('class', 'y')]
stats_df = []
single_val_c = {}
for i, c in enumerate(feature_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()
    df = pd.DataFrame(index=range(len(m)))
    df['col'] = c
    df['val'] = m.index.values
    df['positive_percentage'] = m.values
    df['quantity_percentage'] = s.values / s.sum()
    stats_df.append(df)
    trace_prate = go.Bar(x=df['val'], y=df['positive_percentage'] * 100, name='positive percentage')
    trace_cnt = go.Bar(x=df['val'], y=df['quantity_percentage'] * 100, name='quantity percentage')
    layout = go.Layout(xaxis=dict(title=c), yaxis=dict(title='positive and quantity percentage'))
    fig = go.Figure(data=[trace_prate, trace_cnt], layout=layout)
    pyo.iplot(fig)
stats_df = pd.concat(stats_df, axis=0)