Great Tables in Python: Make Publication-Quality Tables

Turn a DataFrame into a polished table with Great Tables: titles, number formats, column groups, colored cells, inline sparklines and PNG export.

Great Tables is a Python library for making presentation-ready tables from a pandas or Polars DataFrame. Wrap the data in GT(df), chain methods such as tab_header() and fmt_currency(), and save it with gtsave(). This post uses Great Tables 1.2.0 (pip install great_tables) and pandas 3.0. Saving images needs Chrome or another supported browser installed.

Quick Example

import pandas as pd
from great_tables import GT, loc, md, style

cafes = pd.DataFrame({
    "city": ["Porto", "Ghent", "Lund", "Graz", "Turku"],
    "cafes": [14, 9, 6, 8, 5],
    "revenue": [1_842_500, 1_203_900, 764_300, 918_750, 551_200],
    "growth": [0.124, 0.061, -0.038, 0.092, 0.017],
    "rating": [4.6, 4.4, 4.7, 4.2, 4.5],
})

table = (
    GT(cafes, rowname_col="city")
    .tab_header(title="Café performance, 2026",
                subtitle="Five cities, made-up data")
    .cols_label(cafes="Cafés", revenue="Revenue", growth="Growth",
                rating="Rating")
    .fmt_currency("revenue", currency="USD", decimals=0)
    .fmt_percent("growth", decimals=1, force_sign=True)
    .fmt_number("rating", decimals=1)
    .data_color(columns="growth", palette=["#f4a582", "#f7f7f7", "#92c5de"],
                domain=[-0.15, 0.15])
    .tab_source_note("Growth is year over year.")
)
table.gtsave("great-tables-quick-example.png")
table

Formatted table of five cities with café counts, revenue in dollars, colored growth percentages and ratings

In Jupyter, the last line displays the table. In a script, gtsave() writes the file, and table.show() opens it in a browser.

Group columns with spanners and rows with groups

tab_spanner() puts one heading over several columns. groupname_col groups rows by a column.

regional = cafes.assign(region=["South", "West", "North", "West", "North"])

grouped = (
    GT(regional, rowname_col="city", groupname_col="region")
    .tab_header(title="Café performance by region")
    .cols_label(cafes="Cafés", revenue="Revenue", growth="Growth",
                rating="Rating")
    .tab_spanner(label="Sales", columns=["revenue", "growth"])
    .tab_spanner(label="Operations", columns=["cafes", "rating"])
    .cols_move_to_end(["cafes", "rating"])
    .fmt_currency("revenue", compact=True, decimals=2)
    .fmt_percent("growth", decimals=1, force_sign=True)
)
grouped.gtsave("great-tables-spanners.png")
grouped

Table with Sales and Operations headings over column pairs and rows grouped into South, West and North

compact=True shortens large values to forms like $1.84M.

Highlight specific cells

tab_style() applies a style to a location. loc.body() takes columns and a row condition.

highlighted = (
    GT(cafes, rowname_col="city")
    .cols_label(cafes="Cafés", revenue="Revenue", growth="Growth",
                rating="Rating")
    .fmt_currency("revenue", decimals=0)
    .fmt_percent("growth", decimals=1)
    .tab_style(
        style=[style.fill("#fff3bf"), style.text(weight="bold")],
        locations=loc.body(
            columns="rating",
            rows=lambda df: df["rating"] == df["rating"].max()))
    .tab_style(
        style=style.text(color="#c92a2a"),
        locations=loc.body(columns="growth",
                           rows=lambda df: df["growth"] < 0))
    .tab_source_note(md("**Yellow:** best rating. **Red:** shrinking revenue."))
)
highlighted.gtsave("great-tables-highlight.png")
highlighted

Table with the best rating highlighted in yellow and the negative growth value in red

Add sparklines and bars inside cells

fmt_nanoplot() draws a mini chart from a column holding lists of numbers.

trends = cafes[["city", "revenue"]].copy()
trends["monthly"] = [
    [128, 131, 140, 149, 155, 162, 171, 166, 158, 154, 160, 169],
    [96, 93, 99, 101, 104, 103, 108, 99, 101, 98, 100, 102],
    [70, 69, 68, 66, 67, 63, 62, 60, 61, 59, 60, 59],
    [68, 70, 74, 75, 79, 83, 82, 80, 77, 76, 78, 77],
    [44, 42, 45, 46, 47, 49, 50, 46, 45, 44, 46, 47],
]
trends["quarters"] = [[sum(m[i:i + 3]) for i in range(0, 12, 3)]
                      for m in trends.monthly]

mini = (
    GT(trends, rowname_col="city")
    .cols_label(revenue="Revenue", monthly="Monthly footfall",
                quarters="Quarterly footfall")
    .fmt_currency("revenue", decimals=0)
    .fmt_nanoplot("monthly")
    .fmt_nanoplot("quarters", plot_type="bar")
)
mini.gtsave("great-tables-nanoplots.png")
mini

Table with a line sparkline of monthly values and a small bar chart of quarterly values in each row

Each row's mini chart scales to its own values by default. Pass autoscale=True to give a column one shared y scale.

Save as PNG, PDF or HTML

table.gtsave("[email protected]", zoom=3)      # sharper image
table.gtsave("cafes.pdf")
html = table.as_raw_html()                # for web pages and emails

Great Tables, pandas Styler or Matplotlib?

Need Tool
Titles, spanners, footnotes and polished output Great Tables
Quick conditional formatting in a notebook pandas Styler
A table inside a Matplotlib figure ax.table()
Mini charts you design yourself Matplotlib sparklines

Practical tips

  • Don't modify a DataFrame after passing it to GT(). In 1.2.0, adding a column to it afterward made the earlier table raise a KeyError when saved. Make a copy with assign() instead, as above.
  • Format numbers in the table, not in the DataFrame, so values stay numeric.
  • Show only the decimals readers need, and keep them consistent in a column.
  • Color one or two columns. A table colored everywhere has no focus.
  • Set domain in data_color() so a color means the same value in every report.

Similar Topics