prepare_by_group_trend_graph

prepare_by_group_trend_graph(
    df,
    ts_id,
    group_var,
    var,
    *,
    points=True,
    error_bars=False,
)

Line-plot the mean of var over time, one line per group_var level.

Parameters

Name Type Description Default
df pd.DataFrame Data frame containing the time index, grouping factor and variable. required
ts_id str Time-series identifier column. required
group_var str Grouping column. required
var str Numeric variable to plot. required
points bool Whether to mark each observation with a point. True
error_bars bool Whether to draw standard-error bars (mean +/- se). False

Returns

Name Type Description
ByGroupTrendGraphResult df (columns ts_id, group_var, mean, se) and the Plotly fig.

Examples

Basic — one line per group, tracking a variable’s mean over time:

import expdpy as ex
from expdpy.data import load_kuznets

df = load_kuznets()
ex.prepare_by_group_trend_graph(
    df, ts_id="year", group_var="continent", var="gini_regional"
).fig

Advanced — add standard-error bars and drop the per-observation markers:

ex.prepare_by_group_trend_graph(
    df, ts_id="year", group_var="continent", var="gini_regional",
    error_bars=True, points=False,
).fig