Custom Templates
pandas-cat uses Jinja2 to render HTML reports. A single unified renderer handles all template types. The rendering mode (static or interactive) is auto-detected from a tag inside the template file — no separate renderer flag is needed.
All Jinja2 environments use autoescape=True. User-supplied strings
(column names, dataset title) are escaped at render time — do not mark them
safe again with | safe unless you intend to inject raw HTML.
Template lookup
|
File loaded |
Mode |
Detected via |
|---|---|---|---|
|
|
static |
(no tag — default) |
|
|
static |
(no tag — default) |
|
|
interactive |
|
Any file-system path |
that file |
auto-detected |
tag in file, or static if absent |
Mode declaration tag
Add this Jinja2 comment anywhere in your template to opt into interactive mode (raw data, no SVG pre-rendering):
{# pandas-cat: mode=interactive #}
Omitting the tag causes the engine to treat the template as static (SVG charts are pre-rendered and embedded as base64 strings before the template receives the context).
Creating a custom template
Write a
.html.j2file anywhere on the file system.Add
{# pandas-cat: mode=interactive #}near the top if you want the interactive context (raw data); omit it for the static context (SVG charts).Pass the path to
profile():pandas_cat.profile(df, template="/path/to/my_report.html.j2")
A relative path is resolved from the current working directory. A
ValueErroris raised if the file does not exist.The template receives the full context for its mode as keyword arguments (see the reference sections below). Extra context keys are silently ignored by Jinja2, so your template only needs to reference the variables it uses.
Note
The FileSystemLoader root for a custom template is the directory that
contains the template file. Relative {% include %} or {% extends %}
paths inside the template resolve from that directory.
Keeping the module-level default
template_name is a public module-level variable that controls which
built-in template is used when template=None or template='default':
import pandas_cat
pandas_cat.template_name = "myname.html.j2"
pandas_cat.profile(df)
The named file must live inside pandas_cat/templates/. For templates
outside the package directory, pass a full path instead (see above).
Context reference
The context passed to a template depends on its mode (determined by the
presence or absence of the {# pandas-cat: mode=interactive #} tag).
Common variables
Both modes receive these top-level variables:
Variable |
Type |
Description |
|---|---|---|
|
|
Title shown in the report header. Defaults to |
|
|
pandas-cat version string, e.g. |
|
|
One entry per user-visible warning (column excluded, limit exceeded).
Each item has two string keys: |
|
|
Number of rows in the report DataFrame. |
|
|
Number of columns in the report (after filtering). |
|
|
Total count of missing cells across the whole DataFrame. |
attribute_profiles — fields common to both modes
Every item in attribute_profiles (regardless of mode) includes:
Key |
Type |
Description |
|---|---|---|
|
|
Column name. |
|
|
|
|
|
|
|
|
Missing-value sentinel strings replaced with |
|
|
Replacement counts, parallel to |
Static mode
Templates without the mode tag receive pre-rendered SVG charts. Additional top-level variables beyond the common set:
Variable |
Type |
Description |
|---|---|---|
|
|
Dataset-level summary. See df_summary. |
|
|
One entry per column. Common fields above plus static-specific fields. |
|
|
Correlation charts and raw data. See corr. |
df_summary
Key |
Type |
Description |
|---|---|---|
|
|
Three string entries: |
|
|
One entry per column. See df_summary.Profiles item. |
|
|
Base64-encoded SVG of the stacked memory-usage bar chart.
Empty string |
df_summary.Profiles item
Key |
Type |
Description |
|---|---|---|
|
|
Column name. |
|
|
Number of distinct categories as a string, or |
|
|
Comma-separated list of category values (categorical), or
|
|
|
Raw byte count for this column. |
|
|
Human-readable, e.g. |
attribute_profiles — static additional fields
Each item also contains:
Key |
Type |
Description |
|---|---|---|
|
|
Base64-encoded SVG: histogram+KDE for continuous columns, frequency bar chart for categorical columns. |
|
|
Pre-formatted statistics card. Keys differ by column type — see below. |
|
|
Frequency table rows (categorical only; empty list for continuous). See freq_tbl item. |
summary_tbl keys — categorical column:
"Categories", "Most frequent", "Least frequent",
"Missings", "Memory"
summary_tbl keys — continuous column:
"Mean", "Median", "Std Dev", "Min", "Max",
"Q1 (25%)", "Q3 (75%)", "Missings", "Memory"
freq_tbl item (categorical columns only)
Key |
Type |
Description |
|---|---|---|
|
|
Category value (may be a number, string, or |
|
|
Number of rows with this value. |
|
|
Percentage of total rows as a string, e.g. |
|
|
Raw percentage value (0–100). |
|
|
Width of the frequency bar relative to the most-frequent category,
as a CSS |
corr
Key |
Type |
Description |
|---|---|---|
|
|
Base64-encoded SVG of the Cramér’s V heatmap (all categorical column
pairs). |
|
|
Base64-encoded SVG of the Pearson correlation heatmap (continuous
columns only). |
|
|
Per-column-pair crosstab heatmaps. See corr.indiv_corr. |
|
|
Flat |
|
|
Flat |
corr.indiv_corr
A nested dict keyed by the row column name:
corr.indiv_corr = {
"ColumnA": {
"attribute": "ColumnA", # str — row column name
"vars": {
"ColumnA": "<base64 SVG>", # self-vs-self
"ColumnB": "<base64 SVG>", # ColumnA × ColumnB crosstab
...
}
},
...
}
Only categorical columns appear as keys. Continuous columns are absent from
indiv_corr entirely.
Interactive mode
Templates with {# pandas-cat: mode=interactive #} receive raw data
instead of pre-rendered SVGs. Additional top-level variables beyond the
common set:
Variable |
Type |
Description |
|---|---|---|
|
|
Human-readable total memory usage of the report DataFrame. |
|
|
Columns removed because they exceeded |
|
|
One entry per column. Common fields above plus interactive-specific fields. |
|
|
Correlation matrices as flat |
excluded_attributes item
Key |
Type |
Description |
|---|---|---|
|
|
Column name. |
|
|
Number of distinct categories found (exceeds |
attribute_profiles — interactive additional fields
Each item also contains these fields for every column:
Key |
Type |
Description |
|---|---|---|
|
|
Count of missing values in this column. |
|
|
Human-readable memory usage of this column. |
Additional fields for categorical columns (is_continuous == False):
Key |
Type |
Description |
|---|---|---|
|
|
Category values, in display order (natural for ordered
|
|
|
Row count per category, parallel to |
|
|
Percentage of total rows (including missing) per category, rounded to 2 decimal places. |
Additional fields for continuous columns (is_continuous == True):
Key |
Type |
Description |
|---|---|---|
|
|
Always an empty list. |
|
|
Always an empty list. |
|
|
Always an empty list. |
|
|
Bin midpoints computed by |
|
|
Row count per bin, parallel to |
|
|
Percentage of total rows (including missing) per bin, rounded to 2 decimal places. |
|
|
Descriptive statistics — see stats dict. |
stats dict (continuous columns only)
All values are float, rounded to 6 decimal places.
Key |
Description |
|---|---|
|
Arithmetic mean. |
|
Standard deviation ( |
|
Minimum value. |
|
Maximum value. |
|
Median (50th percentile). |
|
25th percentile. |
|
75th percentile. |
correlations_data
A dict whose values are flat lists of {x, y, v} point dicts:
correlations_data = {
"Cramers V": [{"x": col_a, "y": col_b, "v": float}, ...],
"Spearman Rank":[{"x": col_a, "y": col_b, "v": float}, ...],
"Theils U": [{"x": col_a, "y": col_b, "v": float}, ...],
"<A> x <B>": [{"x": cat_val_a, "y": cat_val_b, "v": float}, ...],
...
}
The three summary keys cover every column in the report. Individual
"<A> x <B>" keys are added only for categorical–categorical pairs.
Key pattern |
Notes |
|---|---|
|
Bergsma-Wicher corrected. Range 0–1. |
|
Range −1–1. Categoricals encoded as integer codes before ranking. Computed for all column pairs including continuous. |
|
Asymmetric uncertainty coefficient. Range 0–1. |
|
Raw crosstab counts for categorical–categorical pairs only.
|