Great Tables 1 in Python: Structure, Format and Style

Authors

Michael Chow

Richard Iannone

Published

April 24, 2025

Code Along: Coffee Table

This workshop (and future video), with presenters Michael Chow and Rich Iannone, is all about using Great Tables to make beautiful tables for publication and display purposes. We believe that effective tables have these things in common:

  1. structuring that aids in the reading of the table
  2. well-formatted values, fitting expectations for the field of study
  3. styling that reduces time to insight and improves aesthetics

1 About The Instructors

Michael Chow, Senior Software Engineer, Posit

Michael is a data scientist and software engineer. He has programmed in Python for well over a decade, and he obtained a PhD in cognitive psychology from Princeton University. His interests include statistical methods, skill acquisition, and human memory.

Richard Iannone, Senior Software Engineer, Posit

Richard is a software engineer and table enthusiast. He’s been vigorously working on making display tables easier to create/display in Python. And generally Rich enjoys creating open source packages so that people can great things in their own work.

Start

Setting up.

Code
import polars as pl
import json
import polars.selectors as cs
import typing_extensions
from great_tables import GT, loc, style

Importing the data.

Code
# Load JSON file
with open("coffee-sales.json", "r") as f:
    raw_data = json.load(f)

# Extract column names
columns = [col["name"] for col in raw_data["columns"]]

# Extract values and convert to rows
values = list(zip(*[col["values"] for col in raw_data["columns"]]))

# Convert to list of dictionaries while extracting only the list from 'monthly_sales'
data = []
for row in values:
    row_dict = dict(zip(columns, row))
    
    # Extract only the list from the "monthly_sales" column
    if "monthly_sales" in row_dict:
        if isinstance(row_dict["monthly_sales"], dict) and "values" in row_dict["monthly_sales"]:
            row_dict["monthly_sales"] = row_dict["monthly_sales"]["values"]  # Extract only the list
    
    data.append(row_dict)

# Create Polars DataFrame
coffee_sales = pl.DataFrame(data)

coffee_sales
shape: (14, 7)
icon product revenue_dollars revenue_pct profit_dollars profit_pct monthly_sales
str str f64 f64 f64 f64 list[i64]
"grinder.png" "Grinder" 904500.0 0.03 567960.0 0.04 [521, 494, … 751]
"moka-pot.png" "Moka pot" 2.04525e6 0.07 181080.0 0.01 [4726, 4741, … 6283]
"cold-brew.png" "Cold brew" 288750.0 0.01 241770.0 0.02 [244, 249, … 244]
"filter.png" "Filter" 404250.0 0.01 70010.0 0.0 [2067, 1809, … 2744]
"drip-machine.png" "Drip machine" 2.632e6 0.09 1.37445e6 0.09 [2137, 1623, … 2328]
"chemex.png" "Chemex" 3.13725e6 0.11 817680.0 0.06 [4938, 4167, … 7220]
"scale.png" "Scale" 3.801e6 0.13 2.91029e6 0.2 [1542, 1566, … 3180]
"kettle.png" "Kettle" 756250.0 0.03 617520.0 0.04 [1139, 1023, … 1529]
"espresso-machine.png" "Espresso Machine" 8.406e6 0.29 3.63644e6 0.25 [686, 840, … 2577]
null "Total" 2.94485e7 1.0 1.479315e7 1.0 null
GT()

Let’s get the data into Great Tables.

Code
gt_tbl_1 = GT(coffee_sales)

gt_tbl_1
icon product revenue_dollars revenue_pct profit_dollars profit_pct monthly_sales
grinder.png Grinder 904500.0 0.03 567960.0 0.04 [521, 494, 596, 613, 667, 748, 765, 686, 607, 594, 568, 751]
moka-pot.png Moka pot 2045250.0 0.07 181080.0 0.01 [4726, 4741, 4791, 5506, 6156, 6619, 6868, 6026, 5304, 4884, 4648, 6283]
cold-brew.png Cold brew 288750.0 0.01 241770.0 0.02 [244, 249, 438, 981, 1774, 2699, 2606, 2348, 1741, 896, 499, 244]
filter.png Filter 404250.0 0.01 70010.0 0.0 [2067, 1809, 1836, 2123, 2252, 2631, 2562, 2367, 2164, 2195, 2070, 2744]
drip-machine.png Drip machine 2632000.0 0.09 1374450.0 0.09 [2137, 1623, 1971, 2097, 2580, 2456, 2336, 2316, 2052, 1967, 1837, 2328]
aeropress.png AeroPress 2601500.0 0.09 1293780.0 0.09 [6332, 5199, 6367, 7024, 7906, 8704, 8693, 7797, 6828, 6963, 6877, 9270]
pour-over.png Pour over 846000.0 0.03 364530.0 0.02 [1562, 1291, 1511, 1687, 1940, 2177, 2141, 1856, 1715, 1806, 1601, 2165]
french-press.png French press 1113250.0 0.04 748120.0 0.05 [3507, 2880, 3346, 3792, 3905, 4095, 4184, 4428, 3279, 3420, 3297, 4819]
cezve.png Cezve 2512500.0 0.09 1969520.0 0.13 [12171, 11469, 11788, 13630, 15391, 16532, 17090, 14433, 12985, 12935, 11598, 15895]
chemex.png Chemex 3137250.0 0.11 817680.0 0.06 [4938, 4167, 5235, 6000, 6358, 6768, 7112, 6249, 5605, 6076, 4980, 7220]
scale.png Scale 3801000.0 0.13 2910290.0 0.2 [1542, 1566, 1681, 2028, 2425, 2549, 2569, 2232, 2036, 2089, 1693, 3180]
kettle.png Kettle 756250.0 0.03 617520.0 0.04 [1139, 1023, 1087, 1131, 1414, 1478, 1456, 1304, 1140, 1233, 1193, 1529]
espresso-machine.png Espresso Machine 8406000.0 0.29 3636440.0 0.25 [686, 840, 618, 598, 2148, 533, 797, 996, 1002, 668, 858, 2577]
None Total 29448500.0 1.0 14793150.0 1.0 None
Structure Basics 1

Add a title to the table to explain contents.

Code
gt_tbl_2 = gt_tbl_1.tab_header(
        title = "Coffee Equipment Sales for 2023"
    )

gt_tbl_2
Coffee Equipment Sales for 2023
icon product revenue_dollars revenue_pct profit_dollars profit_pct monthly_sales
grinder.png Grinder 904500.0 0.03 567960.0 0.04 [521, 494, 596, 613, 667, 748, 765, 686, 607, 594, 568, 751]
moka-pot.png Moka pot 2045250.0 0.07 181080.0 0.01 [4726, 4741, 4791, 5506, 6156, 6619, 6868, 6026, 5304, 4884, 4648, 6283]
cold-brew.png Cold brew 288750.0 0.01 241770.0 0.02 [244, 249, 438, 981, 1774, 2699, 2606, 2348, 1741, 896, 499, 244]
filter.png Filter 404250.0 0.01 70010.0 0.0 [2067, 1809, 1836, 2123, 2252, 2631, 2562, 2367, 2164, 2195, 2070, 2744]
drip-machine.png Drip machine 2632000.0 0.09 1374450.0 0.09 [2137, 1623, 1971, 2097, 2580, 2456, 2336, 2316, 2052, 1967, 1837, 2328]
aeropress.png AeroPress 2601500.0 0.09 1293780.0 0.09 [6332, 5199, 6367, 7024, 7906, 8704, 8693, 7797, 6828, 6963, 6877, 9270]
pour-over.png Pour over 846000.0 0.03 364530.0 0.02 [1562, 1291, 1511, 1687, 1940, 2177, 2141, 1856, 1715, 1806, 1601, 2165]
french-press.png French press 1113250.0 0.04 748120.0 0.05 [3507, 2880, 3346, 3792, 3905, 4095, 4184, 4428, 3279, 3420, 3297, 4819]
cezve.png Cezve 2512500.0 0.09 1969520.0 0.13 [12171, 11469, 11788, 13630, 15391, 16532, 17090, 14433, 12985, 12935, 11598, 15895]
chemex.png Chemex 3137250.0 0.11 817680.0 0.06 [4938, 4167, 5235, 6000, 6358, 6768, 7112, 6249, 5605, 6076, 4980, 7220]
scale.png Scale 3801000.0 0.13 2910290.0 0.2 [1542, 1566, 1681, 2028, 2425, 2549, 2569, 2232, 2036, 2089, 1693, 3180]
kettle.png Kettle 756250.0 0.03 617520.0 0.04 [1139, 1023, 1087, 1131, 1414, 1478, 1456, 1304, 1140, 1233, 1193, 1529]
espresso-machine.png Espresso Machine 8406000.0 0.29 3636440.0 0.25 [686, 840, 618, 598, 2148, 533, 797, 996, 1002, 668, 858, 2577]
None Total 29448500.0 1.0 14793150.0 1.0 None
Structure Basics 2

Group numerical columns with a spanner. One grouping should be for revenue columns, another should be for profit columns.

Code
gt_tbl_3 = gt_tbl_2.tab_spanner(
    label="Revenue", columns=cs.starts_with("revenue")
).tab_spanner(  
    label="Profit", columns=cs.starts_with("profit")
)


gt_tbl_3
Coffee Equipment Sales for 2023
icon product Revenue Profit monthly_sales
revenue_dollars revenue_pct profit_dollars profit_pct
grinder.png Grinder 904500.0 0.03 567960.0 0.04 [521, 494, 596, 613, 667, 748, 765, 686, 607, 594, 568, 751]
moka-pot.png Moka pot 2045250.0 0.07 181080.0 0.01 [4726, 4741, 4791, 5506, 6156, 6619, 6868, 6026, 5304, 4884, 4648, 6283]
cold-brew.png Cold brew 288750.0 0.01 241770.0 0.02 [244, 249, 438, 981, 1774, 2699, 2606, 2348, 1741, 896, 499, 244]
filter.png Filter 404250.0 0.01 70010.0 0.0 [2067, 1809, 1836, 2123, 2252, 2631, 2562, 2367, 2164, 2195, 2070, 2744]
drip-machine.png Drip machine 2632000.0 0.09 1374450.0 0.09 [2137, 1623, 1971, 2097, 2580, 2456, 2336, 2316, 2052, 1967, 1837, 2328]
aeropress.png AeroPress 2601500.0 0.09 1293780.0 0.09 [6332, 5199, 6367, 7024, 7906, 8704, 8693, 7797, 6828, 6963, 6877, 9270]
pour-over.png Pour over 846000.0 0.03 364530.0 0.02 [1562, 1291, 1511, 1687, 1940, 2177, 2141, 1856, 1715, 1806, 1601, 2165]
french-press.png French press 1113250.0 0.04 748120.0 0.05 [3507, 2880, 3346, 3792, 3905, 4095, 4184, 4428, 3279, 3420, 3297, 4819]
cezve.png Cezve 2512500.0 0.09 1969520.0 0.13 [12171, 11469, 11788, 13630, 15391, 16532, 17090, 14433, 12985, 12935, 11598, 15895]
chemex.png Chemex 3137250.0 0.11 817680.0 0.06 [4938, 4167, 5235, 6000, 6358, 6768, 7112, 6249, 5605, 6076, 4980, 7220]
scale.png Scale 3801000.0 0.13 2910290.0 0.2 [1542, 1566, 1681, 2028, 2425, 2549, 2569, 2232, 2036, 2089, 1693, 3180]
kettle.png Kettle 756250.0 0.03 617520.0 0.04 [1139, 1023, 1087, 1131, 1414, 1478, 1456, 1304, 1140, 1233, 1193, 1529]
espresso-machine.png Espresso Machine 8406000.0 0.29 3636440.0 0.25 [686, 840, 618, 598, 2148, 533, 797, 996, 1002, 668, 858, 2577]
None Total 29448500.0 1.0 14793150.0 1.0 None
Structure Basics 3

Change Column labels for readability. The column names are: icon, product, revenue_dollars, revenue_pct, profit_dollars, profit_pct, and monthly_sales.

Code
gt_tbl_4 = (
    gt_tbl_3
    .cols_label(
        revenue_dollars="Amount",
        revenue_pct = "Percent",
        profit_dollars="Amount",
        profit_pct = "Percent",
        monthly_sales = "Monthly Sales"
    )
)

gt_tbl_4
Coffee Equipment Sales for 2023
icon product Revenue Profit Monthly Sales
Amount Percent Amount Percent
grinder.png Grinder 904500.0 0.03 567960.0 0.04 [521, 494, 596, 613, 667, 748, 765, 686, 607, 594, 568, 751]
moka-pot.png Moka pot 2045250.0 0.07 181080.0 0.01 [4726, 4741, 4791, 5506, 6156, 6619, 6868, 6026, 5304, 4884, 4648, 6283]
cold-brew.png Cold brew 288750.0 0.01 241770.0 0.02 [244, 249, 438, 981, 1774, 2699, 2606, 2348, 1741, 896, 499, 244]
filter.png Filter 404250.0 0.01 70010.0 0.0 [2067, 1809, 1836, 2123, 2252, 2631, 2562, 2367, 2164, 2195, 2070, 2744]
drip-machine.png Drip machine 2632000.0 0.09 1374450.0 0.09 [2137, 1623, 1971, 2097, 2580, 2456, 2336, 2316, 2052, 1967, 1837, 2328]
aeropress.png AeroPress 2601500.0 0.09 1293780.0 0.09 [6332, 5199, 6367, 7024, 7906, 8704, 8693, 7797, 6828, 6963, 6877, 9270]
pour-over.png Pour over 846000.0 0.03 364530.0 0.02 [1562, 1291, 1511, 1687, 1940, 2177, 2141, 1856, 1715, 1806, 1601, 2165]
french-press.png French press 1113250.0 0.04 748120.0 0.05 [3507, 2880, 3346, 3792, 3905, 4095, 4184, 4428, 3279, 3420, 3297, 4819]
cezve.png Cezve 2512500.0 0.09 1969520.0 0.13 [12171, 11469, 11788, 13630, 15391, 16532, 17090, 14433, 12985, 12935, 11598, 15895]
chemex.png Chemex 3137250.0 0.11 817680.0 0.06 [4938, 4167, 5235, 6000, 6358, 6768, 7112, 6249, 5605, 6076, 4980, 7220]
scale.png Scale 3801000.0 0.13 2910290.0 0.2 [1542, 1566, 1681, 2028, 2425, 2549, 2569, 2232, 2036, 2089, 1693, 3180]
kettle.png Kettle 756250.0 0.03 617520.0 0.04 [1139, 1023, 1087, 1131, 1414, 1478, 1456, 1304, 1140, 1233, 1193, 1529]
espresso-machine.png Espresso Machine 8406000.0 0.29 3636440.0 0.25 [686, 840, 618, 598, 2148, 533, 797, 996, 1002, 668, 858, 2577]
None Total 29448500.0 1.0 14793150.0 1.0 None
Formatting Basics 1

Format the currency values to make them look better.

Code
gt_tbl_5 =  (
    gt_tbl_4
    .fmt_currency(columns=cs.ends_with("dollars"),
                 use_subunits=False
                 )
)

gt_tbl_5
Coffee Equipment Sales for 2023
icon product Revenue Profit Monthly Sales
Amount Percent Amount Percent
grinder.png Grinder $904,500 0.03 $567,960 0.04 [521, 494, 596, 613, 667, 748, 765, 686, 607, 594, 568, 751]
moka-pot.png Moka pot $2,045,250 0.07 $181,080 0.01 [4726, 4741, 4791, 5506, 6156, 6619, 6868, 6026, 5304, 4884, 4648, 6283]
cold-brew.png Cold brew $288,750 0.01 $241,770 0.02 [244, 249, 438, 981, 1774, 2699, 2606, 2348, 1741, 896, 499, 244]
filter.png Filter $404,250 0.01 $70,010 0.0 [2067, 1809, 1836, 2123, 2252, 2631, 2562, 2367, 2164, 2195, 2070, 2744]
drip-machine.png Drip machine $2,632,000 0.09 $1,374,450 0.09 [2137, 1623, 1971, 2097, 2580, 2456, 2336, 2316, 2052, 1967, 1837, 2328]
aeropress.png AeroPress $2,601,500 0.09 $1,293,780 0.09 [6332, 5199, 6367, 7024, 7906, 8704, 8693, 7797, 6828, 6963, 6877, 9270]
pour-over.png Pour over $846,000 0.03 $364,530 0.02 [1562, 1291, 1511, 1687, 1940, 2177, 2141, 1856, 1715, 1806, 1601, 2165]
french-press.png French press $1,113,250 0.04 $748,120 0.05 [3507, 2880, 3346, 3792, 3905, 4095, 4184, 4428, 3279, 3420, 3297, 4819]
cezve.png Cezve $2,512,500 0.09 $1,969,520 0.13 [12171, 11469, 11788, 13630, 15391, 16532, 17090, 14433, 12985, 12935, 11598, 15895]
chemex.png Chemex $3,137,250 0.11 $817,680 0.06 [4938, 4167, 5235, 6000, 6358, 6768, 7112, 6249, 5605, 6076, 4980, 7220]
scale.png Scale $3,801,000 0.13 $2,910,290 0.2 [1542, 1566, 1681, 2028, 2425, 2549, 2569, 2232, 2036, 2089, 1693, 3180]
kettle.png Kettle $756,250 0.03 $617,520 0.04 [1139, 1023, 1087, 1131, 1414, 1478, 1456, 1304, 1140, 1233, 1193, 1529]
espresso-machine.png Espresso Machine $8,406,000 0.29 $3,636,440 0.25 [686, 840, 618, 598, 2148, 533, 797, 996, 1002, 668, 858, 2577]
None Total $29,448,500 1.0 $14,793,150 1.0 None
Formatting Basics 2

Format the fractional values by turning them into percentages.

Code
gt_tbl_6 = (
    gt_tbl_5
    .fmt_percent(
        columns =cs.ends_with("pct"),
        decimals=0
    )
)

gt_tbl_6
Coffee Equipment Sales for 2023
icon product Revenue Profit Monthly Sales
Amount Percent Amount Percent
grinder.png Grinder $904,500 3% $567,960 4% [521, 494, 596, 613, 667, 748, 765, 686, 607, 594, 568, 751]
moka-pot.png Moka pot $2,045,250 7% $181,080 1% [4726, 4741, 4791, 5506, 6156, 6619, 6868, 6026, 5304, 4884, 4648, 6283]
cold-brew.png Cold brew $288,750 1% $241,770 2% [244, 249, 438, 981, 1774, 2699, 2606, 2348, 1741, 896, 499, 244]
filter.png Filter $404,250 1% $70,010 0% [2067, 1809, 1836, 2123, 2252, 2631, 2562, 2367, 2164, 2195, 2070, 2744]
drip-machine.png Drip machine $2,632,000 9% $1,374,450 9% [2137, 1623, 1971, 2097, 2580, 2456, 2336, 2316, 2052, 1967, 1837, 2328]
aeropress.png AeroPress $2,601,500 9% $1,293,780 9% [6332, 5199, 6367, 7024, 7906, 8704, 8693, 7797, 6828, 6963, 6877, 9270]
pour-over.png Pour over $846,000 3% $364,530 2% [1562, 1291, 1511, 1687, 1940, 2177, 2141, 1856, 1715, 1806, 1601, 2165]
french-press.png French press $1,113,250 4% $748,120 5% [3507, 2880, 3346, 3792, 3905, 4095, 4184, 4428, 3279, 3420, 3297, 4819]
cezve.png Cezve $2,512,500 9% $1,969,520 13% [12171, 11469, 11788, 13630, 15391, 16532, 17090, 14433, 12985, 12935, 11598, 15895]
chemex.png Chemex $3,137,250 11% $817,680 6% [4938, 4167, 5235, 6000, 6358, 6768, 7112, 6249, 5605, 6076, 4980, 7220]
scale.png Scale $3,801,000 13% $2,910,290 20% [1542, 1566, 1681, 2028, 2425, 2549, 2569, 2232, 2036, 2089, 1693, 3180]
kettle.png Kettle $756,250 3% $617,520 4% [1139, 1023, 1087, 1131, 1414, 1478, 1456, 1304, 1140, 1233, 1193, 1529]
espresso-machine.png Espresso Machine $8,406,000 29% $3,636,440 25% [686, 840, 618, 598, 2148, 533, 797, 996, 1002, 668, 858, 2577]
None Total $29,448,500 100% $14,793,150 100% None
Styling with tab_style() 1

Add an ‘aliceblue’ background to columns pertaining to revenue.

Code
gt_tbl_7 = (
    gt_tbl_6
    .tab_style(
        style= style.fill(color="aliceblue"),
        locations=loc.body(columns=cs.starts_with("revenue"))
    )
)

gt_tbl_7
Coffee Equipment Sales for 2023
icon product Revenue Profit Monthly Sales
Amount Percent Amount Percent
grinder.png Grinder $904,500 3% $567,960 4% [521, 494, 596, 613, 667, 748, 765, 686, 607, 594, 568, 751]
moka-pot.png Moka pot $2,045,250 7% $181,080 1% [4726, 4741, 4791, 5506, 6156, 6619, 6868, 6026, 5304, 4884, 4648, 6283]
cold-brew.png Cold brew $288,750 1% $241,770 2% [244, 249, 438, 981, 1774, 2699, 2606, 2348, 1741, 896, 499, 244]
filter.png Filter $404,250 1% $70,010 0% [2067, 1809, 1836, 2123, 2252, 2631, 2562, 2367, 2164, 2195, 2070, 2744]
drip-machine.png Drip machine $2,632,000 9% $1,374,450 9% [2137, 1623, 1971, 2097, 2580, 2456, 2336, 2316, 2052, 1967, 1837, 2328]
aeropress.png AeroPress $2,601,500 9% $1,293,780 9% [6332, 5199, 6367, 7024, 7906, 8704, 8693, 7797, 6828, 6963, 6877, 9270]
pour-over.png Pour over $846,000 3% $364,530 2% [1562, 1291, 1511, 1687, 1940, 2177, 2141, 1856, 1715, 1806, 1601, 2165]
french-press.png French press $1,113,250 4% $748,120 5% [3507, 2880, 3346, 3792, 3905, 4095, 4184, 4428, 3279, 3420, 3297, 4819]
cezve.png Cezve $2,512,500 9% $1,969,520 13% [12171, 11469, 11788, 13630, 15391, 16532, 17090, 14433, 12985, 12935, 11598, 15895]
chemex.png Chemex $3,137,250 11% $817,680 6% [4938, 4167, 5235, 6000, 6358, 6768, 7112, 6249, 5605, 6076, 4980, 7220]
scale.png Scale $3,801,000 13% $2,910,290 20% [1542, 1566, 1681, 2028, 2425, 2549, 2569, 2232, 2036, 2089, 1693, 3180]
kettle.png Kettle $756,250 3% $617,520 4% [1139, 1023, 1087, 1131, 1414, 1478, 1456, 1304, 1140, 1233, 1193, 1529]
espresso-machine.png Espresso Machine $8,406,000 29% $3,636,440 25% [686, 840, 618, 598, 2148, 533, 797, 996, 1002, 668, 858, 2577]
None Total $29,448,500 100% $14,793,150 100% None
Styling with tab_style() 2

Add an ‘papayawhip’ background to columns pertaining to profit.

Code
gt_tbl_8 = (
    gt_tbl_7
    .tab_style(
        style= style.fill(color="papayawhip"),
        locations=loc.body(columns=cs.starts_with("profit"))
    )
)

gt_tbl_8
Coffee Equipment Sales for 2023
icon product Revenue Profit Monthly Sales
Amount Percent Amount Percent
grinder.png Grinder $904,500 3% $567,960 4% [521, 494, 596, 613, 667, 748, 765, 686, 607, 594, 568, 751]
moka-pot.png Moka pot $2,045,250 7% $181,080 1% [4726, 4741, 4791, 5506, 6156, 6619, 6868, 6026, 5304, 4884, 4648, 6283]
cold-brew.png Cold brew $288,750 1% $241,770 2% [244, 249, 438, 981, 1774, 2699, 2606, 2348, 1741, 896, 499, 244]
filter.png Filter $404,250 1% $70,010 0% [2067, 1809, 1836, 2123, 2252, 2631, 2562, 2367, 2164, 2195, 2070, 2744]
drip-machine.png Drip machine $2,632,000 9% $1,374,450 9% [2137, 1623, 1971, 2097, 2580, 2456, 2336, 2316, 2052, 1967, 1837, 2328]
aeropress.png AeroPress $2,601,500 9% $1,293,780 9% [6332, 5199, 6367, 7024, 7906, 8704, 8693, 7797, 6828, 6963, 6877, 9270]
pour-over.png Pour over $846,000 3% $364,530 2% [1562, 1291, 1511, 1687, 1940, 2177, 2141, 1856, 1715, 1806, 1601, 2165]
french-press.png French press $1,113,250 4% $748,120 5% [3507, 2880, 3346, 3792, 3905, 4095, 4184, 4428, 3279, 3420, 3297, 4819]
cezve.png Cezve $2,512,500 9% $1,969,520 13% [12171, 11469, 11788, 13630, 15391, 16532, 17090, 14433, 12985, 12935, 11598, 15895]
chemex.png Chemex $3,137,250 11% $817,680 6% [4938, 4167, 5235, 6000, 6358, 6768, 7112, 6249, 5605, 6076, 4980, 7220]
scale.png Scale $3,801,000 13% $2,910,290 20% [1542, 1566, 1681, 2028, 2425, 2549, 2569, 2232, 2036, 2089, 1693, 3180]
kettle.png Kettle $756,250 3% $617,520 4% [1139, 1023, 1087, 1131, 1414, 1478, 1456, 1304, 1140, 1233, 1193, 1529]
espresso-machine.png Espresso Machine $8,406,000 29% $3,636,440 25% [686, 840, 618, 598, 2148, 533, 797, 996, 1002, 668, 858, 2577]
None Total $29,448,500 100% $14,793,150 100% None
Styling with tab_style() 3

Make the text bold in the bottom row (the totals column).

Code
gt_tbl_9 = (
    gt_tbl_8
    .tab_style(
        style=style.text(weight="bold"),
        locations=loc.body(rows= pl.col("product") == "Total"
    )
)
)

gt_tbl_9
Coffee Equipment Sales for 2023
icon product Revenue Profit Monthly Sales
Amount Percent Amount Percent
grinder.png Grinder $904,500 3% $567,960 4% [521, 494, 596, 613, 667, 748, 765, 686, 607, 594, 568, 751]
moka-pot.png Moka pot $2,045,250 7% $181,080 1% [4726, 4741, 4791, 5506, 6156, 6619, 6868, 6026, 5304, 4884, 4648, 6283]
cold-brew.png Cold brew $288,750 1% $241,770 2% [244, 249, 438, 981, 1774, 2699, 2606, 2348, 1741, 896, 499, 244]
filter.png Filter $404,250 1% $70,010 0% [2067, 1809, 1836, 2123, 2252, 2631, 2562, 2367, 2164, 2195, 2070, 2744]
drip-machine.png Drip machine $2,632,000 9% $1,374,450 9% [2137, 1623, 1971, 2097, 2580, 2456, 2336, 2316, 2052, 1967, 1837, 2328]
aeropress.png AeroPress $2,601,500 9% $1,293,780 9% [6332, 5199, 6367, 7024, 7906, 8704, 8693, 7797, 6828, 6963, 6877, 9270]
pour-over.png Pour over $846,000 3% $364,530 2% [1562, 1291, 1511, 1687, 1940, 2177, 2141, 1856, 1715, 1806, 1601, 2165]
french-press.png French press $1,113,250 4% $748,120 5% [3507, 2880, 3346, 3792, 3905, 4095, 4184, 4428, 3279, 3420, 3297, 4819]
cezve.png Cezve $2,512,500 9% $1,969,520 13% [12171, 11469, 11788, 13630, 15391, 16532, 17090, 14433, 12985, 12935, 11598, 15895]
chemex.png Chemex $3,137,250 11% $817,680 6% [4938, 4167, 5235, 6000, 6358, 6768, 7112, 6249, 5605, 6076, 4980, 7220]
scale.png Scale $3,801,000 13% $2,910,290 20% [1542, 1566, 1681, 2028, 2425, 2549, 2569, 2232, 2036, 2089, 1693, 3180]
kettle.png Kettle $756,250 3% $617,520 4% [1139, 1023, 1087, 1131, 1414, 1478, 1456, 1304, 1140, 1233, 1193, 1529]
espresso-machine.png Espresso Machine $8,406,000 29% $3,636,440 25% [686, 840, 618, 598, 2148, 533, 797, 996, 1002, 668, 858, 2577]
None Total $29,448,500 100% $14,793,150 100% None
Three Last Things 1

Add a column of bar plots using the monthly revenue column.

Code
gt_tbl_10 = (
    gt_tbl_9
    .fmt_nanoplot(
        columns="monthly_sales",
        plot_type="bar"
    )
)

gt_tbl_10
Coffee Equipment Sales for 2023
icon product Revenue Profit Monthly Sales
Amount Percent Amount Percent
grinder.png Grinder $904,500 3% $567,960 4%
7650521494596613667748765686607594568751
moka-pot.png Moka pot $2,045,250 7% $181,080 1%
6.87K04.73K4.74K4.79K5.51K6.16K6.62K6.87K6.03K5.30K4.88K4.65K6.28K
cold-brew.png Cold brew $288,750 1% $241,770 2%
2.70K02442494389811.77K2.70K2.61K2.35K1.74K896499244
filter.png Filter $404,250 1% $70,010 0%
2.74K02.07K1.81K1.84K2.12K2.25K2.63K2.56K2.37K2.16K2.19K2.07K2.74K
drip-machine.png Drip machine $2,632,000 9% $1,374,450 9%
2.58K02.14K1.62K1.97K2.10K2.58K2.46K2.34K2.32K2.05K1.97K1.84K2.33K
aeropress.png AeroPress $2,601,500 9% $1,293,780 9%
9.27K06.33K5.20K6.37K7.02K7.91K8.70K8.69K7.80K6.83K6.96K6.88K9.27K
pour-over.png Pour over $846,000 3% $364,530 2%
2.18K01.56K1.29K1.51K1.69K1.94K2.18K2.14K1.86K1.72K1.81K1.60K2.16K
french-press.png French press $1,113,250 4% $748,120 5%
4.82K03.51K2.88K3.35K3.79K3.90K4.10K4.18K4.43K3.28K3.42K3.30K4.82K
cezve.png Cezve $2,512,500 9% $1,969,520 13%
17.1K012.2K11.5K11.8K13.6K15.4K16.5K17.1K14.4K13.0K12.9K11.6K15.9K
chemex.png Chemex $3,137,250 11% $817,680 6%
7.22K04.94K4.17K5.24K6.00K6.36K6.77K7.11K6.25K5.60K6.08K4.98K7.22K
scale.png Scale $3,801,000 13% $2,910,290 20%
3.18K01.54K1.57K1.68K2.03K2.42K2.55K2.57K2.23K2.04K2.09K1.69K3.18K
kettle.png Kettle $756,250 3% $617,520 4%
1.53K01.14K1.02K1.09K1.13K1.41K1.48K1.46K1.30K1.14K1.23K1.19K1.53K
espresso-machine.png Espresso Machine $8,406,000 29% $3,636,440 25%
2.58K06868406185982.15K5337979961.00K6688582.58K
None Total $29,448,500 100% $14,793,150 100% None
Three Last Things 2

Add images to the icon column. The images are in the img directory.

Code
gt_tbl_11 = (
    gt_tbl_10.fmt_image(
    columns="icon",
    path=r"C:\Users\Hon.Olayinka\Documents\GitHub\Posit_PBC\GREAT_TABLES_PYTHON\Lesson_1\img"  
)
)

gt_tbl_11
Coffee Equipment Sales for 2023
icon product Revenue Profit Monthly Sales
Amount Percent Amount Percent
Grinder $904,500 3% $567,960 4%
7650521494596613667748765686607594568751
Moka pot $2,045,250 7% $181,080 1%
6.87K04.73K4.74K4.79K5.51K6.16K6.62K6.87K6.03K5.30K4.88K4.65K6.28K
Cold brew $288,750 1% $241,770 2%
2.70K02442494389811.77K2.70K2.61K2.35K1.74K896499244
Filter $404,250 1% $70,010 0%
2.74K02.07K1.81K1.84K2.12K2.25K2.63K2.56K2.37K2.16K2.19K2.07K2.74K
Drip machine $2,632,000 9% $1,374,450 9%
2.58K02.14K1.62K1.97K2.10K2.58K2.46K2.34K2.32K2.05K1.97K1.84K2.33K
AeroPress $2,601,500 9% $1,293,780 9%
9.27K06.33K5.20K6.37K7.02K7.91K8.70K8.69K7.80K6.83K6.96K6.88K9.27K
Pour over $846,000 3% $364,530 2%
2.18K01.56K1.29K1.51K1.69K1.94K2.18K2.14K1.86K1.72K1.81K1.60K2.16K
French press $1,113,250 4% $748,120 5%
4.82K03.51K2.88K3.35K3.79K3.90K4.10K4.18K4.43K3.28K3.42K3.30K4.82K
Cezve $2,512,500 9% $1,969,520 13%
17.1K012.2K11.5K11.8K13.6K15.4K16.5K17.1K14.4K13.0K12.9K11.6K15.9K
Chemex $3,137,250 11% $817,680 6%
7.22K04.94K4.17K5.24K6.00K6.36K6.77K7.11K6.25K5.60K6.08K4.98K7.22K
Scale $3,801,000 13% $2,910,290 20%
3.18K01.54K1.57K1.68K2.03K2.42K2.55K2.57K2.23K2.04K2.09K1.69K3.18K
Kettle $756,250 3% $617,520 4%
1.53K01.14K1.02K1.09K1.13K1.41K1.48K1.46K1.30K1.14K1.23K1.19K1.53K
Espresso Machine $8,406,000 29% $3,636,440 25%
2.58K06868406185982.15K5337979961.00K6688582.58K
None Total $29,448,500 100% $14,793,150 100% None
Three Last Things 3

Turn the None cells into blank cells.

Code
gt_tbl_12 = (
    gt_tbl_11
    .sub_missing(missing_text="")
)

gt_tbl_12
Coffee Equipment Sales for 2023
icon product Revenue Profit Monthly Sales
Amount Percent Amount Percent
Grinder $904,500 3% $567,960 4%
7650521494596613667748765686607594568751
Moka pot $2,045,250 7% $181,080 1%
6.87K04.73K4.74K4.79K5.51K6.16K6.62K6.87K6.03K5.30K4.88K4.65K6.28K
Cold brew $288,750 1% $241,770 2%
2.70K02442494389811.77K2.70K2.61K2.35K1.74K896499244
Filter $404,250 1% $70,010 0%
2.74K02.07K1.81K1.84K2.12K2.25K2.63K2.56K2.37K2.16K2.19K2.07K2.74K
Drip machine $2,632,000 9% $1,374,450 9%
2.58K02.14K1.62K1.97K2.10K2.58K2.46K2.34K2.32K2.05K1.97K1.84K2.33K
AeroPress $2,601,500 9% $1,293,780 9%
9.27K06.33K5.20K6.37K7.02K7.91K8.70K8.69K7.80K6.83K6.96K6.88K9.27K
Pour over $846,000 3% $364,530 2%
2.18K01.56K1.29K1.51K1.69K1.94K2.18K2.14K1.86K1.72K1.81K1.60K2.16K
French press $1,113,250 4% $748,120 5%
4.82K03.51K2.88K3.35K3.79K3.90K4.10K4.18K4.43K3.28K3.42K3.30K4.82K
Cezve $2,512,500 9% $1,969,520 13%
17.1K012.2K11.5K11.8K13.6K15.4K16.5K17.1K14.4K13.0K12.9K11.6K15.9K
Chemex $3,137,250 11% $817,680 6%
7.22K04.94K4.17K5.24K6.00K6.36K6.77K7.11K6.25K5.60K6.08K4.98K7.22K
Scale $3,801,000 13% $2,910,290 20%
3.18K01.54K1.57K1.68K2.03K2.42K2.55K2.57K2.23K2.04K2.09K1.69K3.18K
Kettle $756,250 3% $617,520 4%
1.53K01.14K1.02K1.09K1.13K1.41K1.48K1.46K1.30K1.14K1.23K1.19K1.53K
Espresso Machine $8,406,000 29% $3,636,440 25%
2.58K06868406185982.15K5337979961.00K6688582.58K
Total $29,448,500 100% $14,793,150 100%