explore_ext_obs_table

source

explore_ext_obs_table(
    df,
    n=5,
    var=None,
    *,
    entity=None,
    time=None,
    digits=3,
    title=None,
    subtitle=None,
)

Display the top and bottom n observations sorted by var.

Parameters

Name Type Description Default
df pd.DataFrame Data frame. required
n int Number of extreme observations on each side (2 * n <= len(df)). 5
var str | None Variable to sort by (must be numeric). Defaults to the last numeric column that is not an identifier. None
entity Sequence[str] | str | None Cross-sectional identifier column(s). Defaults to the panel entity declared via :func:expdpy.set_panel. If both entity and time are unset (and none is declared), all variables are tabulated; otherwise only the identifiers and var. None
time str | None Time identifier column. Defaults to the panel time. None
digits int Number of decimals for numeric cells. 3

Returns

Name Type Description
ExtObsTableResult df (the 2 * n extreme rows) and gt (a Great Tables object grouping the highest and lowest blocks).

Examples

Basic — the five highest and lowest observations (sorted by the last numeric column), tabulating all variables:

import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def

df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ex.explore_ext_obs_table(df, n=5).gt
Country Year Log GDP per capita³
Highest 5
country 79 2,021.000 1,692.984
country 79 2,020.000 1,692.984
country 69 2,023.000 1,692.984
country 69 2,025.000 1,692.984
country 69 2,024.000 1,692.984
Lowest 5
country 4 2,022.000 267.195
country 4 2,021.000 264.063
country 4 2,023.000 257.634
country 4 2,024.000 255.737
country 4 2,025.000 247.060

Advanced — the ten most extreme observations of a chosen variable, showing only the panel identifiers and that variable (the panel is taken from the declared entity/time):

import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def

df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ex.explore_ext_obs_table(df, n=10, var="gini_regional").gt
Country Year Regional inequality (Gini)
Highest 10
country 80 2,023.000 0.568
country 80 2,024.000 0.539
country 69 2,025.000 0.532
country 80 2,022.000 0.528
country 79 2,021.000 0.524
country 28 2,018.000 0.516
country 79 2,025.000 0.513
country 69 2,024.000 0.511
country 79 2,023.000 0.510
country 28 2,025.000 0.509
Lowest 10
country 1 2,015.000 0.086
country 43 2,021.000 0.084
country 1 2,016.000 0.080
country 4 2,017.000 0.065
country 16 2,025.000 0.057
country 4 2,020.000 0.035
country 4 2,021.000 0.033
country 4 2,023.000 0.020
country 4 2,024.000 0.020
country 4 2,025.000 0.020