prepare_correlation_table
prepare_correlation_table(df, digits=2, bold=0.05, *, caption=None)Correlation table with Pearson above and Spearman below the diagonal.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| df | pd.DataFrame | Data frame with at least two numeric/logical variables and five observations. | required |
| digits | int | Number of decimals to display (0 < digits < 5). |
2 |
| bold | float | Correlations with a p-value below bold are shown in bold. Set to 0 to disable. Must satisfy 0 <= bold < 1. |
0.05 |
| caption | str | None | Optional table title. | None |
Returns
| Name | Type | Description |
|---|---|---|
| CorrelationTableResult | df_corr/df_prob/df_n (numeric matrices keyed by the original variable names) and gt (a Great Tables object using letter labels). |
Examples
Basic — Pearson (above) and Spearman (below) correlations for a few variables:
import expdpy as ex
from expdpy.data import load_kuznets
df = load_kuznets()
ex.prepare_correlation_table(df[["gini_regional", "gdp_pc", "log_gdp_pc"]]).gtAdvanced — more decimals, a stricter bold threshold, a caption, and the raw coefficient/p-value matrices from .df_corr / .df_prob:
result = ex.prepare_correlation_table(
df[["gini_regional", "gdp_pc", "log_gdp_pc", "trade_share"]],
digits=3,
bold=0.01,
caption="Correlations (kuznets)",
)
result.gt
result.df_corr
result.df_prob