change

change(df, variables=None, first=None, last=None)

The change of each unit between two years of a panel, one row per unit.

Parameters

Name Type Description Default
df pd.DataFrame A long panel with geo_id, year and variables (e.g. from geo.load) required
variables A variable or list of them (default: every numeric variable) None
first int | None The two years to compare (default: the panel’s first and last year) None
last int | None The two years to compare (default: the panel’s first and last year) None

Returns

Name Type Description
pandas.DataFrame One row per unit. For each variable v: v_<first>, v_<last>, v_change (last minus first), v_pct_change (in percent of the first value), v_annual_change (the change divided by the years between them), v_rank_<first> and v_rank_<last> (1 = highest value) and v_rank_change (positive when the unit climbed). Text columns that are constant within a unit (name, department…) are kept. The years are the stored years: for panels stored at nominal years (see geo.reference_years), the actual span of an indicator may differ.

Example

!pip install -q geo4bolivia
import geo4bolivia as geo
import plotly.express as px

df = geo.load("sdg01", variables="sdg1_2_mpi", groups=["department"])
chg = geo.change(df, "sdg1_2_mpi")
px.scatter(chg, x="sdg1_2_mpi_2012", y="sdg1_2_mpi_change",
           color="department", hover_name="name", labels=geo.labels(chg),
           title="Poverty fell most where it was highest")