Notebook
from prettytable import PrettyTable from ipywidgets import interact, widgets import numpy as np from IPython.core.display import display, HTML from matplotlib import pyplot as plt def cast(v): try: return float(v) except: return np.nan @interact(variable=data.columns.sort_values()) def categorical_table(variable='V161267', zoom=widgets.IntSlider(min=10,max=100,step=5,value=10),drop_na=False): df = data.copy() df[variable] = df[variable].apply(cast) if drop_na: df = df[df[variable] > 0] x = PrettyTable() x.field_names = [variable, 'mean', 'standard deviation'] mu = np.mean(df[variable]) sigma = np.std(df[variable]) result = (variable, mu, sigma) x.add_row(result) display(HTML(x.get_html_string())) plt.figure(figsize=(10,5)) plt.hist(df[variable], bins=zoom) ax = plt.gca() ymin, ymax = ax.get_ylim() for val in range(-3,3): x = val*sigma+mu col='black' if val==0: ax.vlines(x,ymin,ymax, alpha=1, color='red') else: ax.vlines(x,ymin,ymax/np.abs(val)/(zoom/10), alpha=1/np.abs(val), color=col)