prepare_bar_chart

prepare_bar_chart(df, var, *, order_by_count=False, color='#4682b4')

Bar chart of category counts for a (typically categorical) variable.

Parameters

Name Type Description Default
df pd.DataFrame Data frame containing var. required
var str Column whose value counts are charted. required
order_by_count bool If True, bars are ordered by descending count; otherwise by category. False
color str Bar fill color. '#4682b4'

Returns

Name Type Description
BarChartResult df (columns var and count) and the Plotly fig.

Examples

Basic — category counts of a (typically categorical) variable:

import expdpy as ex
from expdpy.data import load_kuznets

df = load_kuznets()
ex.prepare_bar_chart(df, "continent").fig

Advanced — order bars by descending count and set a custom color:

ex.prepare_bar_chart(df, "continent", order_by_count=True, color="red").fig