prepare_histogram

prepare_histogram(df, var, *, bins=30)

Histogram of a numeric variable.

Parameters

Name Type Description Default
df pd.DataFrame Data frame containing var. required
var str Numeric column to bin. required
bins int Number of equal-width bins. 30

Returns

Name Type Description
HistogramResult df (columns bin_left, bin_right, count) and the Plotly fig.

Examples

Basic — a 30-bin histogram of a numeric variable:

import expdpy as ex
from expdpy.data import load_kuznets

df = load_kuznets()
ex.prepare_histogram(df, "gini_regional").fig

Advanced — finer bins, with the bin/count table from .df:

result = ex.prepare_histogram(df, "gdp_pc", bins=50)
result.fig
result.df.head()