Commercial enterprise offerings

Creating Great Tables in Python: Answering your questions

Isabella Velásquez's head shot
Written by Isabella Velásquez
2025-02-13
Great Tables + Python

Get our email updates

Interested in learning more about Posit + Python tools? Join our email list.

The Great Tables package makes creating polished and professional display tables in Python easier than ever. And let us tell you, Great Tables is great!

Since its debut, the package has seen a flurry of updates and new features. As a relatively new package, we’re eager to hear your feedback! Questions, feature requests, or bug reports — let us know through GitHub Issues or our community Discord server.

If you’re new to Great Tables, watch how Ryan Johnson uses Python to create a table in under 60 seconds:

In this post, we’re answering frequently asked questions to help you make the most of Great Tables, especially if you haven’t explored its latest updates yet. Let’s get started!

How to download Great Tables as an image file

The 0.3.1 release introduces the .save() method for exporting images. To use this feature, be sure to install the pillow and selenium packages.

from great_tables import GT
from great_tables.data import gtcars
import polars as pl

gtcars_mini = (
    pl.from_pandas(gtcars)
    .select(["mfr", "model", "msrp"])
    .head(5)
)

gt_tbl = (
    GT(gtcars_mini)
    .tab_header(
        title="Data Listing from the gtcars Dataset",
        subtitle="Only five rows from the dataset are shown here."
    )
    .fmt_currency(columns="msrp")
)
gt_tbl.save("gt_output.png")

Learn more in the GT.save documentation.

How to embed Great Tables in an email/HTML webpage

The 0.3.1 release also introduces the .as_raw_html() method for embedding tables into emails or HTML webpages. The as_raw_html() method contains the inline_css argument. When set to True, it automatically converts styles from the <style> block into inline styles for elements like <tr> and <td>. This is especially useful for HTML emails, where inline styles ensure better compatibility across a wide range of email clients.

gt_tbl.as_raw_html(inline_css=True)

Learn more in the .as_raw_html documentation.

How to output LaTeX in Great Tables

The as_latex() method generates LaTeX strings when building tables if used as the last invocation. To use it with Quarto, make sure to call print() on the resulting object to render the LaTeX table properly.

print(gt_tbl.as_latex())
\begin{table}
\caption*{
{\large Data Listing from the gtcars Dataset} \\
{\small Only five rows from the dataset are shown here.}
} 

\fontsize{12.0pt}{14.4pt}\selectfont

\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}llr}
\toprule
mfr & model & msrp \\ 
\midrule\addlinespace[2.5pt]
Ford & GT & \$447,000.00 \\
Ferrari & 458 Speciale & \$291,744.00 \\
Ferrari & 458 Spider & \$263,553.00 \\
Ferrari & 458 Italia & \$233,509.00 \\
Ferrari & 488 GTB & \$245,400.00 \\
\bottomrule
\end{tabular*}

\end{table}

Check out the API reference article and accompanying blog post to see some examples. Finally, note that this method is marked as Experimental and may be subject to changes. Please report any issues should you find them.

How to add strings wherever there are nulls in Great Tables

To replace null values with alternate text, use the sub_missing() method.

from great_tables import GT, md, html, exibble
import polars as pl
import polars.selectors as cs

exibble_mini = pl.from_pandas(exibble).drop("row", "group", "fctr").slice(4, 8)

(
    GT(exibble_mini)
    .sub_missing(
        columns=["num", "char"],
        missing_text="missing"
    )
    .sub_missing(
        columns=cs.contains(("date", "time")) | cs.by_name("currency"),
        missing_text="nothing"
    )
)
num char date time datetime currency
5550.0 missing 2015-05-15 17:55 2018-05-05 04:00 1325.81
missing fig 2015-06-15 nothing 2018-06-06 16:11 13.255
777000.0 grapefruit nothing 19:10 2018-07-07 05:22 nothing
8880000.0 honeydew 2015-08-15 20:20 nothing 0.44

For a usage example, check out the API reference (scroll to the bottom of the page).

How to create interactive tables in Python with reactable-py

Here’s a twist: you won’t need Great Tables for this one! Meet reactable-py, a new Python library designed for interactively viewing DataFrames. It offers quick options for sorting, searching, and paginating your data.

Read more about reactable-py.

Stay up-to-date on making great Python tables

We’ve covered some of the latest features and updates to help you create great-looking, interactive tables in Python with Great Tables and reactable-py. If you have any questions, run into issues, or have suggestions for future updates, don’t hesitate to reach out. The community is here to help, and we look forward to seeing what you create with these tools!

Isabella Velásquez's head shot

Isabella Velásquez

Sr. Product Marketing Manager at Posit, PBC
Isabella is a content strategist, data enthusiast, and author. Her goal is to drive engagement around all the awesome things happening at Posit.