text_html_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train_data = pd.read_json('../input/train.json')
display_count = 3
target = 'interest_level'

train_data.iloc[0]

def get_value_counts(col, df):
    return pd.DataFrame(df[col].value_counts())

global_bar_chart_settings = {'height': 4, 'width': 8, 'bar_width': 0.9, 'title': 'Number of occurrences of ', 'ylabel': 'Occurrence', 'alpha': None, 'lbl_fontsize': 15, 'title_fontsize': 20}

def plot_bar(chart_settings, df, column):
    width = global_bar_chart_settings['width']
    height = global_bar_chart_settings['height']
    alpha = global_bar_chart_settings['alpha']
    title = global_bar_chart_settings['title']
    bar_width = global_bar_chart_settings['bar_width']
    ylabel = global_bar_chart_settings['ylabel']
    lbl_fontsize = global_bar_chart_settings['lbl_fontsize']
    title_fontsize = global_bar_chart_settings['title_fontsize']
    
    chart_keys = chart_settings.keys()
    if 'width' in chart_keys:
        width = chart_settings['width']
    if 'height' in chart_keys:
        height = chart_settings['height']
    if 'title' in chart_keys:
        title = chart_settings['title']
    if 'bar_width' in chart_keys:
        bar_width = chart_settings['bar_width']
    if 'lbl_fontsize' in chart_keys:
        lbl_fontsize = chart_settings['lbl_fontsize']
    if 'title_fontsize' in chart_keys:
        title_fontsize = chart_settings['title_fontsize']
    
    fig, ax = plt.subplots(figsize = (width, height))
    ind = np.arange(len(df.index))
    values = df[column]
    rects = ax.bar(ind, values, bar_width, alpha=alpha)
    ax.set_ylabel(ylabel, fontsize=lbl_fontsize)
    ax.set_title(title + column, fontsize=title_fontsize)
    ax.set_xticks(ind + 0.1 / 2)
    ax.set_xticklabels(df.index)
    plt.show()

uniq_interest_levels = list(train_data[target].unique())
interest_level_groups = train_data.groupby(target)
uniq_interest_levels

title = 'Number of occurrences in high interest level for '
plot_bar({'title': title, 'title_fontsize': 15}, get_value_counts('bathrooms', interest_level_groups.get_group('high')), 'bathrooms')