set_labels

set_labels(df, labels=None, *, set_panel=False)

Declare human-readable variable labels on df and return it.

The labels are stored under df.attrs["geometrics_labels"] so that subsequent explore_* / analyze_* calls can title axes, legends and table headers with them. Explicit label= arguments to those functions still take precedence.

Parameters

Name Type Description Default
df pd.DataFrame The data frame (modified in place — its attrs are updated and the same object is returned). required
labels Mapping[str, str] | pd.DataFrame | None Either a {column_name: label} mapping, or a data-dictionary frame (df_dict) whose label / var_def columns supply the labels. None leaves the stored mapping unchanged. None
set_panel bool When True and labels is a df_dict, also declare the structural metadata it carries: the panel (entity / time, plus an entity_name column tagged role == "entity_name") via :func:~geometrics.set_panel, and the analytical roles (role of outcome / covariate) via :func:~geometrics.set_roles. False

Returns

Name Type Description
pandas.DataFrame The same df, with df.attrs["geometrics_labels"] updated.

Examples

Declare labels once, then explore with readable titles:

import pandas as pd

import geometrics as gm

df = pd.DataFrame({"region": ["A", "B"], "gini": [0.42, 0.35]})
df = gm.set_labels(df, {"gini": "Regional inequality (Gini)"})