Car Performance Review | |||||||
Using gt-extras functionality | |||||||
Car | mfr | year | hp | trq | mpg_c | mpg_h | efficiency |
---|---|---|---|---|---|---|---|
California | 2015 | 553.0
|
557.0
|
||||
GTC4Lusso | 2017 | 680.0
|
514.0
|
||||
FF | 2015 | 652.0
|
504.0
|
||||
F12Berlinetta | 2015 | 731.0
|
509.0
|
||||
LaFerrari | 2015 | 949.0
|
664.0
|
||||
NSX | 2017 | 573.0
|
476.0
|
||||
GT-R | 2016 | 545.0
|
436.0
|
||||
Aventador | 2015 | 700.0
|
507.0
|
||||
Huracan | 2015 | 610.0
|
413.0
|
||||
Gallardo | 2014 | 550.0
|
398.0
|
||||
Continental GT | 2016 | 500.0
|
487.0
|
||||
Granturismo | 2016 | 454.0
|
384.0
|
||||
Quattroporte | 2016 | 404.0
|
406.0
|
||||
Ghibli | 2016 | 345.0
|
369.0
|
||||
6-Series | 2016 | 315.0
|
330.0
|
||||
i8 | 2016 | 357.0
|
420.0
|
Examples With Code
Mega Examples
Cars
from great_tables import GT
from great_tables.data import gtcars
import gt_extras as gte
# Setup dataframe
= gtcars.iloc[5:21].copy().reset_index(drop=True)
gtcars_mini "efficiency"] = gtcars_mini["mpg_c"] / gtcars_mini["hp"] * 100
gtcars_mini[
(# Start with a standard GT
="model")
GT(gtcars_mini, rowname_col="Car")
.tab_stubhead(label"drivetrain", "hp_rpm", "trq_rpm", "trim", "bdy_style", "msrp", "trsmn", "ctry_origin"])
.cols_hide(["center")
.cols_align(="Car Performance Review", subtitle="Using gt-extras functionality")
.tab_header(title
# Add gt-extras features using gt.pipe()
=["hp", "trq"], palette=["lightblue", "darkblue"])
.pipe(gte.gt_color_box, columns="mfr", data_col="efficiency", domain=[0, 0])
.pipe(gte.gt_plt_dot, category_col=["mpg_c", "mpg_h"])
.pipe(gte.gt_plt_bar, columns="efficiency")
.pipe(gte.gt_fa_rating, columns="year", palette="viridis")
.pipe(gte.gt_hulk_col_numeric, columns
.pipe(gte.gt_theme_538) )
NFL 2011 Season
2011 NFL Season at a Glance
Super Bowl XLVI: New York Giants def. New England Patriots
Team | Record | Scoring | Season Trends | |||
---|---|---|---|---|---|---|
Points For vs Points Against | Point Diff | Games | Streak | |||
AFC East | ||||||
NE | ![]() |
14-2-0 | 11.9
|
7
|
||
MIA | ![]() |
10-6-0 | -1.1
|
-1
|
||
BUF | ![]() |
7-9-0 | 1.3
|
-2
|
||
NYJ | ![]() |
5-11-0 | -8.4
|
1
|
||
AFC North | ||||||
PIT | ![]() |
11-5-0 | 4.5
|
7
|
||
BAL | ![]() |
8-8-0 | 1.4
|
-2
|
||
CIN | ![]() |
6-9-1 | 0.6
|
1
|
||
CLE | ![]() |
1-15-0 | -11.8
|
-1
|
||
AFC South | ||||||
TEN | ![]() |
9-7-0 | 0.2
|
1
|
||
HOU | ![]() |
9-7-0 | -3.1
|
-1
|
||
IND | ![]() |
8-8-0 | 1.2
|
1
|
||
JAX | ![]() |
3-13-0 | -5.1
|
-1
|
||
AFC West | ||||||
KC | ![]() |
12-4-0 | 4.9
|
2
|
||
OAK | ![]() |
12-4-0 | 1.9
|
-1
|
||
DEN | ![]() |
9-7-0 | 2.2
|
1
|
||
SD | ![]() |
5-11-0 | -0.8
|
-5
|
||
Source: Lee Sharpe, nflverse |
Team | Record | Scoring | Season Trends | |||
---|---|---|---|---|---|---|
Points For vs Points Against | Point Diff | Games | Streak | |||
NFC East | ||||||
DAL | ![]() |
13-3-0 | 7.2
|
-1
|
||
NYG | ![]() |
11-5-0 | 1.6
|
1
|
||
WAS | ![]() |
8-7-1 | 0.8
|
-1
|
||
PHI | ![]() |
7-9-0 | 2.2
|
2
|
||
NFC North | ||||||
GB | ![]() |
10-6-0 | 2.8
|
6
|
||
DET | ![]() |
9-7-0 | -0.8
|
-3
|
||
MIN | ![]() |
8-8-0 | 1.2
|
1
|
||
CHI | ![]() |
3-13-0 | -7.5
|
-4
|
||
NFC South | ||||||
ATL | ![]() |
11-5-0 | 8.4
|
4
|
||
TB | ![]() |
9-7-0 | -0.9
|
1
|
||
NO | ![]() |
7-9-0 | 0.9
|
-1
|
||
CAR | ![]() |
6-10-0 | -2.1
|
-2
|
||
NFC West | ||||||
SEA | ![]() |
10-5-1 | 3.9
|
1
|
||
ARI | ![]() |
7-8-1 | 3.5
|
2
|
||
LA | ![]() |
4-12-0 | -10.6
|
-7
|
||
SF | ![]() |
2-14-0 | -10.7
|
-1
|
||
Source: Lee Sharpe, nflverse |
import polars as pl
from great_tables import GT, md
import gt_extras as gte
= pl.read_json("./nfl-season/nfl_2011_stats.json")
nfl_df
def make_gt(df) -> GT:
return (
="Team", groupname_col="team_division")
GT(df, rowname_col
.tab_header(="2011 NFL Season at a Glance",
title="Super Bowl XLVI: New York Giants def. New England Patriots",
subtitle
)
.tab_source_note(
md('<span style="float: right;">Source: [Lee Sharpe, nflverse](https://github.com/nflverse/nfldata)</span>'
)
)="Team")
.tab_stubhead(label="Scoring", columns=["Avg PF", "Avg PA", "Point Diff"])
.tab_spanner(label="Season Trends", columns=["Games", "Streak"])
.tab_spanner(label="Point Diff", decimals=1)
.fmt_number(columns"team_logo_espn")
.fmt_image("Wins", "team_conf", "team_name"])
.cols_hide([="center", columns=["Avg PF", "Avg PA", "Games"])
.cols_align(align"team_logo_espn", after="Team")
.cols_move("team_logo_espn": ""})
.cols_label({
.pipe(
gte.gt_plt_winloss,="Games",
column="blue",
win_color="orange",
loss_color="gray",
tie_color=40,
height=120,
width
)
.pipe(
gte.gt_fa_rank_change,="Streak",
column="turn",
icon_type="blue",
color_up="orange",
color_down=14,
size
)
.pipe(
gte.gt_plt_dumbbell,="Avg PF",
col1="Avg PA",
col2="green",
col1_color="red",
col2_color=300,
width=40,
height=0,
num_decimals="Points For vs Points Against",
label=12,
font_size
)
.pipe(
gte.gt_color_box,="Point Diff",
columns=["green", "yellow", "red"],
palette=[14, -14]
domain
)="Team", fill="lightgray")
.pipe(gte.gt_highlight_cols, columns="NYG", fill="gold", alpha=0.3)
.pipe(gte.gt_highlight_rows, rows="NE", fill="silver", alpha=0.3)
.pipe(gte.gt_highlight_rows, rows="Point Diff", color="darkblue", weight=3)
.pipe(gte.gt_add_divider, columns
.pipe(gte.gt_theme_538)
)
= make_gt(nfl_df.head(16))
gt1 = make_gt(nfl_df.slice(16, 16))
gt2
=1) gte.gt_two_column_layout(gt1, gt2, table_header_from
Gini Coefficient
Setup
import polars as pl
= "gini_market__age_total"
pre_tax_col = "gini_disposable__age_total"
post_tax_col
# Read the data
= pl.read_csv(
df "https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-08-05/income_inequality_raw.csv",
={
schema"Entity": pl.String,
"Code": pl.String,
"Year": pl.Int64,
post_tax_col: pl.Float64,
pre_tax_col: pl.Float64,"population_historical": pl.Int64,
"owid_region": pl.String,
},=["NA", ""],
null_values
)
# Propogate the region field to all rows of that country
= (
df "Entity")
df.sort("Entity", maintain_order=True)
.group_by(
.agg(
["Code"),
pl.col("Year"),
pl.col(
pl.col(post_tax_col),
pl.col(pre_tax_col),"population_historical"),
pl.col(# Most important action happens here
"owid_region").fill_null(strategy="backward"),
pl.col(
]
)
.explode(
["Code",
"Year",
post_tax_col,
pre_tax_col,"population_historical",
"owid_region",
]
)
)
# Drop rows where there is a null in either pre-tax or post-tax cols
= df.drop_nulls(
df =(
subset
pl.col(post_tax_col),
pl.col(pre_tax_col),
)
)
# Compute the percent reduction in gini coefficient.
= df.with_columns(
df - pl.col(post_tax_col)) / pl.col(pre_tax_col) * 100)
((pl.col(pre_tax_col) round(2)
."gini_pct_change")
.alias(
)
# Calculate 5-year benchmark (mean) of percent change for each country
= df.with_columns(
df "gini_pct_change")
pl.col(=5)
.rolling_mean(window_size"Entity"))
.over(pl.col("gini_pct_benchmark_5yr")
.alias(
)
# Select rows with large population in the year 2020, sorted by coefficient post-tax
= (
df # Choose a smaller pop to include more countries
filter(pl.col("population_historical").gt(40000000))
df.filter(pl.col("Year").eq(2020))
.=pl.col(post_tax_col))
.sort(by
)
# Scale population
= df.with_columns((pl.col("population_historical").log10()).alias("pop_log"))
df = df["pop_log"].min() / 1
pop_min = df["pop_log"].max()
pop_max
# Set up gt-extras icons, scaling population to 1-10 range
= df.with_columns(
df "pop_log") - pop_min) / (pop_max - pop_min) * 10 + 1)
((pl.col(round(0)
.
.cast(pl.Int64)"pop_icons")
.alias(
)
# Format original population value with commas
= df.with_columns(
df "population_historical").map_elements(
pl.col(lambda x: f"{int(x):,}" if x is not None else None, return_dtype=pl.String
) )
Income Inequality Before and After Taxes in 2020 | ||||
As measured by the Gini coefficient, where 0 is best and 1 is worst | ||||
Pre-tax to Post-tax Coefficient | Population | Improvement Post Taxes | ||
---|---|---|---|---|
Europe | ||||
France |
65,905,226
|
|||
Germany |
83,628,661
|
|||
Spain |
47,679,437
|
|||
Italy |
59,912,714
|
|||
United Kingdom |
67,351,806
|
|||
Asia | ||||
South Korea |
51,858,440
|
|||
Turkey |
86,091,644
|
|||
North America | ||||
United States |
339,436,106
|
|||
Mexico |
126,798,998
|
|||
South America | ||||
Brazil |
208,660,785
|
|||
from great_tables import GT, html
import gt_extras as gte
# Apply gte.fa_icon_repeat to each entry in the pop_icons column
= df.with_columns(
df_with_icons "pop_icons").map_elements(
pl.col(lambda x: gte.fa_icon_repeat(name="person", repeats=int(x)),
=pl.String,
return_dtype
)
)
# Generate the table, before gt-extras add-ons
= (
gt ="Entity", groupname_col="owid_region")
GT(df_with_icons, rowname_col
.tab_header("Income Inequality Before and After Taxes in 2020",
"As measured by the Gini coefficient, where 0 is best and 1 is worst",
)"pop_icons", after=pre_tax_col)
.cols_move("left")
.cols_align("Year", "pop_log", "population_historical"])
.cols_hide(["Code")
.fmt_flag(
.cols_label(
{"Code": "",
"gini_pct_change": "Improvement Post Taxes",
"pop_icons": "Population",
}
)
.tab_source_note(
html("""
<div>
<strong>Source:</strong> Data from <a href="https://github.com/rfordatascience/tidytuesday">#TidyTuesday</a> (2025-08-05).<br>
<div>
<strong>Dumbbell plot:</strong>
<span style="color:#106ea0;">Blue:</span> post-tax Gini coefficient
<span style="color:#e0b165;">Gold:</span> pre-tax Gini coefficient
<br>
</div>
<strong>Bullet plot:</strong> Percent reduction in Gini after taxes for each country, compared to its 5-year average benchmark.
</div>
"""
)
)
)
# Apply the gt-extras functions via pipe
(
gt.pipe(
gte.gt_plt_dumbbell,=pre_tax_col,
col1=post_tax_col,
col2="#e0b165",
col1_color="#106ea0",
col2_color="transparent",
dot_border_color=2,
num_decimals=240,
width="Pre-tax to Post-tax Coefficient",
label
)
.pipe(
gte.gt_plt_bullet,"gini_pct_change",
"gini_pct_benchmark_5yr",
="#963d4c",
fill="#3D3D3D",
target_color=15,
bar_height=200,
width
)
.pipe(
gte.gt_merge_stack,="pop_icons",
col1="population_historical",
col2
)
.pipe(gte.gt_theme_guardian) )
Plotting
gt_plt_bar
Car | mfr | year | hp | hp_rpm | trq | trq_rpm | mpg_c | mpg_h |
---|---|---|---|---|---|---|---|---|
LaFerrari | Ferrari | 2015 | ||||||
NSX | Acura | 2017 | ||||||
GT-R | Nissan | 2016 | ||||||
Aventador | Lamborghini | 2015 | ||||||
Huracan | Lamborghini | 2015 | ||||||
Gallardo | Lamborghini | 2014 | ||||||
Continental GT | Bentley | 2016 | ||||||
Granturismo | Maserati | 2016 | ||||||
Quattroporte | Maserati | 2016 |
from great_tables import GT
from great_tables.data import gtcars
import gt_extras as gte
= gtcars.loc[
gtcars_mini 9:17,
"model", "mfr", "year", "hp", "hp_rpm", "trq", "trq_rpm", "mpg_c", "mpg_h"]
[
]
= (
gt ="model")
GT(gtcars_mini, rowname_col="Car")
.tab_stubhead(label"center")
.cols_align("left", columns="mfr")
.cols_align(
)
gt.pipe(
gte.gt_plt_bar,= ["hp", "hp_rpm", "trq", "trq_rpm", "mpg_c", "mpg_h"]
columns )
gt_plt_bar_pct
x | autoscale_on | autoscale_off |
---|---|---|
10 | ||
20 | ||
30 | ||
40 |
import polars as pl
from great_tables import GT
import gt_extras as gte
= pl.DataFrame({"x": [10, 20, 30, 40]}).with_columns(
df "x").alias("autoscale_on"),
pl.col("x").alias("autoscale_off"),
pl.col(
)
= GT(df)
gt
(
gt.pipe(
gte.gt_plt_bar_pct,=["autoscale_on"],
column=True,
autoscale=True,
labels="green",
fill
).pipe(
gte.gt_plt_bar_pct,=["autoscale_off"],
column=False,
autoscale=True,
labels
) )
gt_plt_bar_stack
x | Group 1 | Group 2 | Group 3 |
---|---|
Example A | |
Example B | |
Example C |
import pandas as pd
from great_tables import GT
import gt_extras as gte
= pd.DataFrame({
df "x": ["Example A", "Example B", "Example C"],
"col": [
10, 40, 50],
[30, 30, 40],
[50, 20, 30],
[
],
})
= GT(df)
gt
gt.pipe(
gte.gt_plt_bar_stack,="col",
column=["red", "grey", "black"],
palette=["Group 1", "Group 2", "Group 3"],
labels=200,
width )
gt_plt_bullet
Daily Temp vs Monthly Average | ||
Temp plot | Temp | |
---|---|---|
5/1 | 67 | |
5/2 | 72 | |
6/1 | 78 | |
6/2 | 74 | |
7/1 | 84 | |
7/2 | 85 | |
8/1 | 81 | |
8/2 | 81 | |
9/1 | 91 | |
9/2 | 92 | |
Target line shows monthly average temperature |
import polars as pl
from great_tables import GT
from great_tables.data import airquality
import gt_extras as gte
= (
air_bullet
pl.from_pandas(airquality)"Temp").mean().over("Month").alias("target_temp"))
.with_columns(pl.col("Month", maintain_order=True)
.group_by(2)
.head(
.with_columns("Month").cast(pl.Utf8) + "/" + pl.col("Day").cast(pl.Utf8)).alias(
(pl.col("Date"
)
)"Date", "Temp", "target_temp"])
.select(["Temp", "target_temp"]).round(1))
.with_columns(pl.col([
)
(="Date")
GT(air_bullet, rowname_col="Daily Temp vs Monthly Average")
.tab_header(title"Target line shows monthly average temperature")
.tab_source_note(
## Call gt_plt_bullet
.pipe(
gte.gt_plt_bullet,="Temp",
data_column="target_temp",
target_column=200,
width="tomato",
fill="darkblue",
target_color=True,
keep_data_column
)"Temp")
.cols_move_to_end("left", "Temp plot")
.cols_align( )
gt_plt_conf_int
group | mean | ci_lower | ci_upper | ci |
---|---|---|---|---|
A | 5.2 | 3.1 | 7.3 | |
B | 7.8 | 6.1 | 9.7 | |
C | 3.4 | 1.8 | 5.0 |
import pandas as pd
from great_tables import GT
import gt_extras as gte
= pd.DataFrame({
df 'group': ['A', 'B', 'C'],
'mean': [5.2, 7.8, 3.4],
'ci_lower': [3.1, 6.1, 1.8],
'ci_upper': [7.3, 9.7, 5.0],
'ci': [5.2, 7.8, 3.4],
})
= GT(df)
gt
gt.pipe(
gte.gt_plt_conf_int,='ci',
column=['ci_lower', 'ci_upper'],
ci_columns=120,
width )
gt_plt_dot
Car | mfr | hp |
---|---|---|
F12Berlinetta | 731.0 | |
LaFerrari | 949.0 | |
NSX | 573.0 | |
GT-R | 545.0 | |
Aventador | 700.0 | |
Huracan | 610.0 | |
Gallardo | 550.0 | |
Continental GT | 500.0 | |
Granturismo | 454.0 | |
Quattroporte | 404.0 | |
Ghibli | 345.0 | |
6-Series | 315.0 | |
i8 | 357.0 |
from great_tables import GT
from great_tables.data import gtcars
import gt_extras as gte
= gtcars.loc[8:20, ["model", "mfr", "hp"]]
gtcars_mini
= (
gt ="model")
GT(gtcars_mini, rowname_col="Car")
.tab_stubhead(label
)
="mfr", data_col="hp") gt.pipe(gte.gt_plt_dot, category_col
gt_plt_dumbbell
date | Open to Close ($) |
---|---|
2008-12-03 | |
2008-12-04 | |
2008-12-05 | |
2008-12-08 | |
2008-12-09 | |
2008-12-10 | |
2008-12-11 | |
2008-12-12 | |
2008-12-15 | |
Purple: Open Green: Close |
import pandas as pd
from great_tables import GT, html, style, loc
from great_tables.data import sp500
import gt_extras as gte
# Trim the data to December 2008
= sp500[["date", "open", "close"]].copy()
df "date"] = pd.to_datetime(df["date"], errors='coerce')
df[
= df[
dec_2008 "date"].dt.month == 12) &
(df["date"].dt.year == 2008)
(df[
]= dec_2008.iloc[::-1].iloc[2:11]
dec_2008
# Make the Great Table
= (
gt
GT(dec_2008)"Purple: Open<br>Green: Close"))
.tab_source_note(html(
.tab_style(=style.text(align="right"),
style=[loc.source_notes()]
locations
)
)
gt.pipe(
gte.gt_plt_dumbbell,='open',
col1='close',
col2= "Open to Close ($)",
label =0,
num_decimals=300,
width=60,
height )
gt_plt_summary
Summary Table | ||||||
45 rows x 5 cols | ||||||
Type | Column | Plot Overview | Missing | Mean | Median | SD |
---|---|---|---|---|---|---|
Date | 0.0% | — | — | — | ||
Value | 11.1% | 22.50 | 21.00 | 8.83 | ||
Category | 22.2% | — | — | — | ||
Boolean | 0.0% | 0.67 | — | — | ||
Status | 33.3% | — | — | — |
import polars as pl
from great_tables import GT
import gt_extras as gte
from datetime import datetime
= pl.DataFrame({
df "Date": [
2024, 1, 1),
datetime(2024, 1, 2),
datetime(2024, 1, 7),
datetime(2024, 1, 8),
datetime(2024, 1, 13),
datetime(2024, 1, 16),
datetime(2024, 1, 20),
datetime(2024, 1, 22),
datetime(2024, 2, 1),
datetime(* 5,
] "Value": [10, 15, 20, None, 25, 18, 22, 30, 40] * 5,
"Category": ["A", "B", "C", "A", "B", "C", "D", None, None] * 5,
"Boolean": [True, False, True] * 15,
"Status": ["Active", "Inactive", None] * 15,
})
gte.gt_plt_summary(df)
gt_plt_winloss
Team | 10 Games |
---|---|
Liverpool | |
Chelsea | |
Man City |
from great_tables import GT, md
import gt_extras as gte
import pandas as pd
= pd.DataFrame(
df
{"Team": ["Liverpool", "Chelsea", "Man City"],
"10 Games": [
1, 1, 0, 1, 0.5, 1, 0, 1, 1, 0],
[0, 0, 1, 0, 1, 1, 1, 0, 1, 1],
[0.5, 1, 0.5, 0, 1, 0, 1, 0.5, 1, 0],
[
],
}
)
= GT(df)
gt
gt.pipe(
gte.gt_plt_winloss,="10 Games",
column="green",
win_color )
Coloring
gt_color_box
Island | size |
---|---|
Asia | 16988
|
Africa | 11506
|
North America | 9390
|
South America | 6795
|
Antarctica | 5500
|
Europe | 3745
|
Australia | 2968
|
Greenland | 840
|
New Guinea | 306
|
Borneo | 280
|
from great_tables import GT
from great_tables.data import islands
import gt_extras as gte
= (
islands_mini
islands="size", ascending=False)
.sort_values(by10)
.head(
)
= (
gt ="name")
GT(islands_mini, rowname_col="Island")
.tab_stubhead(label
)
="size", palette=["lightblue", "navy"]) gt.pipe(gte.gt_color_box, columns
gt_data_color_by_group
Color by Group | Color All | |
---|---|---|
grp_a | ||
row_1 | 0.1111 | 0.1111 |
row_2 | 2.222 | 2.222 |
row_3 | 33.33 | 33.33 |
row_4 | 444.4 | 444.4 |
grp_b | ||
row_5 | 5550.0 | 5550.0 |
row_6 | ||
row_7 | 777000.0 | 777000.0 |
row_8 | 8880000.0 | 8880000.0 |
Left: gt_data_color_by_group , Right: data_color |
from great_tables import GT, md
from great_tables.data import exibble
import gt_extras as gte
= (
gt ="row", groupname_col="group")
GT(exibble, rowname_col=None)
.cols_hide(columns"num")
.cols_unhide("num": "Color by Group"})
.cols_label({="num", dupe_name="Color All")
.pipe(gte.gt_duplicate_column, column"Left: `gt_data_color_by_group`, Right: `data_color`"))
.tab_source_note(md(
)
(
gt="Color All", palette="PiYG")
.data_color(columns=["num"], palette="PiYG")
.pipe(gte.gt_data_color_by_group, columns )
gt_highlight_cols
Car | year | hp | trq | mpg_h |
---|---|---|---|---|
GT | 2017 | 647.0 | 550.0 | 18.0 |
458 Speciale | 2015 | 597.0 | 398.0 | 17.0 |
458 Spider | 2015 | 562.0 | 398.0 | 17.0 |
458 Italia | 2014 | 562.0 | 398.0 | 17.0 |
488 GTB | 2016 | 661.0 | 561.0 | 22.0 |
California | 2015 | 553.0 | 557.0 | 23.0 |
GTC4Lusso | 2017 | 680.0 | 514.0 | 17.0 |
FF | 2015 | 652.0 | 504.0 | 16.0 |
from great_tables import GT, md
from great_tables.data import gtcars
import gt_extras as gte
= gtcars[["model", "year", "hp", "trq", "mpg_h"]].head(8)
gtcars_mini
= (
gt ="model")
GT(gtcars_mini, rowname_col=md("*Car*"))
.tab_stubhead(label
)
(
gt="hp")
.pipe(gte.gt_highlight_cols, columns="mpg_h", fill="darkorchid")
.pipe(gte.gt_highlight_cols, columns )
gt_highlight_rows
Car | year | hp | trq |
---|---|---|---|
GT | 2017 | 647.0 | 550.0 |
458 Speciale | 2015 | 597.0 | 398.0 |
458 Spider | 2015 | 562.0 | 398.0 |
458 Italia | 2014 | 562.0 | 398.0 |
488 GTB | 2016 | 661.0 | 561.0 |
California | 2015 | 553.0 | 557.0 |
GTC4Lusso | 2017 | 680.0 | 514.0 |
FF | 2015 | 652.0 | 504.0 |
from great_tables import GT, md
from great_tables.data import gtcars
import gt_extras as gte
= gtcars[["model", "year", "hp", "trq"]].head(8)
gtcars_mini
= (
gt ="model")
GT(gtcars_mini, rowname_col=md("*Car*"))
.tab_stubhead(label
)
(
gt=2, fill="#007FFF")
.pipe(gte.gt_highlight_rows, rows=3, fill="chartreuse")
.pipe(gte.gt_highlight_rows, rows=7, fill="#FF007F")
.pipe(gte.gt_highlight_rows, rows )
gt_hulk_col_numeric
Car | mfr | year | hp | trq | mpg_h |
---|---|---|---|---|---|
GT | Ford | 2017 | 647.0 | 550.0 | 18.0 |
458 Speciale | Ferrari | 2015 | 597.0 | 398.0 | 17.0 |
458 Spider | Ferrari | 2015 | 562.0 | 398.0 | 17.0 |
458 Italia | Ferrari | 2014 | 562.0 | 398.0 | 17.0 |
488 GTB | Ferrari | 2016 | 661.0 | 561.0 | 22.0 |
California | Ferrari | 2015 | 553.0 | 557.0 | 23.0 |
GTC4Lusso | Ferrari | 2017 | 680.0 | 514.0 | 17.0 |
FF | Ferrari | 2015 | 652.0 | 504.0 | 16.0 |
F12Berlinetta | Ferrari | 2015 | 731.0 | 509.0 | 16.0 |
from great_tables import GT
from great_tables.data import gtcars
import gt_extras as gte
= gtcars.loc[0:8, ["model", "mfr", "year", "hp", "trq", "mpg_h"]]
gtcars_mini
= (
gt ="model")
GT(gtcars_mini, rowname_col="Car")
.tab_stubhead(label
)
=["hp", "trq", "mpg_h"]) gt.pipe(gte.gt_hulk_col_numeric, columns
Themes
Setup themes
from great_tables import GT, html
import gt_extras as gte
from great_tables.data import airquality
# Prepare the dataset
= airquality.head(10).assign(Year=1973)
airquality_mini
# Create the base table
= (
gt
GT(airquality_mini)
.tab_header(="Default Theme",
title="New York Air Quality Measurements",
subtitle
)="Time", columns=["Year", "Month", "Day"])
.tab_spanner(label
.tab_spanner(="Measurement",
label=["Ozone", "Solar_R", "Wind", "Temp"],
columns
)=["Year", "Month", "Day"])
.cols_move_to_start(columns
.cols_label(=html("Ozone,<br>ppbV"),
Ozone=html("Solar R.,<br>cal/m<sup>2</sup>"),
Solar_R=html("Wind,<br>mph"),
Wind=html("Temp,<br>°F"),
Temp
)
)
gt
Default Theme | ||||||
New York Air Quality Measurements | ||||||
Time | Measurement | |||||
---|---|---|---|---|---|---|
Year | Month | Day | Ozone, ppbV |
Solar R., cal/m2 |
Wind, mph |
Temp, °F |
1973 | 5 | 1 | 41.0 | 190.0 | 7.4 | 67 |
1973 | 5 | 2 | 36.0 | 118.0 | 8.0 | 72 |
1973 | 5 | 3 | 12.0 | 149.0 | 12.6 | 74 |
1973 | 5 | 4 | 18.0 | 313.0 | 11.5 | 62 |
1973 | 5 | 5 | 14.3 | 56 | ||
1973 | 5 | 6 | 28.0 | 14.9 | 66 | |
1973 | 5 | 7 | 23.0 | 299.0 | 8.6 | 65 |
1973 | 5 | 8 | 19.0 | 99.0 | 13.8 | 59 |
1973 | 5 | 9 | 8.0 | 19.0 | 20.1 | 61 |
1973 | 5 | 10 | 194.0 | 8.6 | 69 |
gt_theme_538
FiveThirtyEight Theme | ||||||
Time | Measurement | |||||
---|---|---|---|---|---|---|
Year | Month | Day | Ozone, ppbV |
Solar R., cal/m2 |
Wind, mph |
Temp, °F |
1973 | 5 | 1 | 41.0 | 190.0 | 7.4 | 67 |
1973 | 5 | 2 | 36.0 | 118.0 | 8.0 | 72 |
1973 | 5 | 3 | 12.0 | 149.0 | 12.6 | 74 |
1973 | 5 | 4 | 18.0 | 313.0 | 11.5 | 62 |
1973 | 5 | 5 | 14.3 | 56 | ||
1973 | 5 | 6 | 28.0 | 14.9 | 66 | |
1973 | 5 | 7 | 23.0 | 299.0 | 8.6 | 65 |
1973 | 5 | 8 | 19.0 | 99.0 | 13.8 | 59 |
1973 | 5 | 9 | 8.0 | 19.0 | 20.1 | 61 |
1973 | 5 | 10 | 194.0 | 8.6 | 69 |
= gt.tab_header(title="FiveThirtyEight Theme")
gt
gt.pipe(gte.gt_theme_538)
gt_theme_espn
ESPN Theme | ||||||
Time | Measurement | |||||
---|---|---|---|---|---|---|
Year | Month | Day | Ozone, ppbV |
Solar R., cal/m2 |
Wind, mph |
Temp, °F |
1973 | 5 | 1 | 41.0 | 190.0 | 7.4 | 67 |
1973 | 5 | 2 | 36.0 | 118.0 | 8.0 | 72 |
1973 | 5 | 3 | 12.0 | 149.0 | 12.6 | 74 |
1973 | 5 | 4 | 18.0 | 313.0 | 11.5 | 62 |
1973 | 5 | 5 | 14.3 | 56 | ||
1973 | 5 | 6 | 28.0 | 14.9 | 66 | |
1973 | 5 | 7 | 23.0 | 299.0 | 8.6 | 65 |
1973 | 5 | 8 | 19.0 | 99.0 | 13.8 | 59 |
1973 | 5 | 9 | 8.0 | 19.0 | 20.1 | 61 |
1973 | 5 | 10 | 194.0 | 8.6 | 69 |
= gt.tab_header(title="ESPN Theme")
gt
gt.pipe(gte.gt_theme_espn)
gt_theme_guardian
Guardian Theme | ||||||
Time | Measurement | |||||
---|---|---|---|---|---|---|
Year | Month | Day | Ozone, ppbV |
Solar R., cal/m2 |
Wind, mph |
Temp, °F |
1973 | 5 | 1 | 41.0 | 190.0 | 7.4 | 67 |
1973 | 5 | 2 | 36.0 | 118.0 | 8.0 | 72 |
1973 | 5 | 3 | 12.0 | 149.0 | 12.6 | 74 |
1973 | 5 | 4 | 18.0 | 313.0 | 11.5 | 62 |
1973 | 5 | 5 | 14.3 | 56 | ||
1973 | 5 | 6 | 28.0 | 14.9 | 66 | |
1973 | 5 | 7 | 23.0 | 299.0 | 8.6 | 65 |
1973 | 5 | 8 | 19.0 | 99.0 | 13.8 | 59 |
1973 | 5 | 9 | 8.0 | 19.0 | 20.1 | 61 |
1973 | 5 | 10 | 194.0 | 8.6 | 69 |
= gt.tab_header(title="Guardian Theme")
gt
gt.pipe(gte.gt_theme_guardian)
gt_theme_nytimes
NYTimes Theme | ||||||
Time | Measurement | |||||
---|---|---|---|---|---|---|
Year | Month | Day | Ozone, ppbV |
Solar R., cal/m2 |
Wind, mph |
Temp, °F |
1973 | 5 | 1 | 41.0 | 190.0 | 7.4 | 67 |
1973 | 5 | 2 | 36.0 | 118.0 | 8.0 | 72 |
1973 | 5 | 3 | 12.0 | 149.0 | 12.6 | 74 |
1973 | 5 | 4 | 18.0 | 313.0 | 11.5 | 62 |
1973 | 5 | 5 | 14.3 | 56 | ||
1973 | 5 | 6 | 28.0 | 14.9 | 66 | |
1973 | 5 | 7 | 23.0 | 299.0 | 8.6 | 65 |
1973 | 5 | 8 | 19.0 | 99.0 | 13.8 | 59 |
1973 | 5 | 9 | 8.0 | 19.0 | 20.1 | 61 |
1973 | 5 | 10 | 194.0 | 8.6 | 69 |
= gt.tab_header(title="NYTimes Theme")
gt
gt.pipe(gte.gt_theme_nytimes)
gt_theme_excel
Excel Theme | ||||||
Time | Measurement | |||||
---|---|---|---|---|---|---|
Year | Month | Day | Ozone, ppbV |
Solar R., cal/m2 |
Wind, mph |
Temp, °F |
1973 | 5 | 1 | 41.0 | 190.0 | 7.4 | 67 |
1973 | 5 | 2 | 36.0 | 118.0 | 8.0 | 72 |
1973 | 5 | 3 | 12.0 | 149.0 | 12.6 | 74 |
1973 | 5 | 4 | 18.0 | 313.0 | 11.5 | 62 |
1973 | 5 | 5 | 14.3 | 56 | ||
1973 | 5 | 6 | 28.0 | 14.9 | 66 | |
1973 | 5 | 7 | 23.0 | 299.0 | 8.6 | 65 |
1973 | 5 | 8 | 19.0 | 99.0 | 13.8 | 59 |
1973 | 5 | 9 | 8.0 | 19.0 | 20.1 | 61 |
1973 | 5 | 10 | 194.0 | 8.6 | 69 |
= gt.tab_header(title="Excel Theme")
gt
gt.pipe(gte.gt_theme_excel)
gt_theme_dot_matrix
Dot Matrix Theme | ||||||
Time | Measurement | |||||
---|---|---|---|---|---|---|
Year | Month | Day | Ozone, ppbV |
Solar R., cal/m2 |
Wind, mph |
Temp, °F |
1973 | 5 | 1 | 41.0 | 190.0 | 7.4 | 67 |
1973 | 5 | 2 | 36.0 | 118.0 | 8.0 | 72 |
1973 | 5 | 3 | 12.0 | 149.0 | 12.6 | 74 |
1973 | 5 | 4 | 18.0 | 313.0 | 11.5 | 62 |
1973 | 5 | 5 | 14.3 | 56 | ||
1973 | 5 | 6 | 28.0 | 14.9 | 66 | |
1973 | 5 | 7 | 23.0 | 299.0 | 8.6 | 65 |
1973 | 5 | 8 | 19.0 | 99.0 | 13.8 | 59 |
1973 | 5 | 9 | 8.0 | 19.0 | 20.1 | 61 |
1973 | 5 | 10 | 194.0 | 8.6 | 69 |
= gt.tab_header(title="Dot Matrix Theme")
gt
gt.pipe(gte.gt_theme_dot_matrix)
gt_theme_dark
Dark Theme | ||||||
Time | Measurement | |||||
---|---|---|---|---|---|---|
Year | Month | Day | Ozone, ppbV |
Solar R., cal/m2 |
Wind, mph |
Temp, °F |
1973 | 5 | 1 | 41.0 | 190.0 | 7.4 | 67 |
1973 | 5 | 2 | 36.0 | 118.0 | 8.0 | 72 |
1973 | 5 | 3 | 12.0 | 149.0 | 12.6 | 74 |
1973 | 5 | 4 | 18.0 | 313.0 | 11.5 | 62 |
1973 | 5 | 5 | 14.3 | 56 | ||
1973 | 5 | 6 | 28.0 | 14.9 | 66 | |
1973 | 5 | 7 | 23.0 | 299.0 | 8.6 | 65 |
1973 | 5 | 8 | 19.0 | 99.0 | 13.8 | 59 |
1973 | 5 | 9 | 8.0 | 19.0 | 20.1 | 61 |
1973 | 5 | 10 | 194.0 | 8.6 | 69 |
= gt.tab_header(title="Dark Theme")
gt
gt.pipe(gte.gt_theme_dark)
gt_theme_pff
PFF Theme | ||||||
Time | Measurement | |||||
---|---|---|---|---|---|---|
Year | Month | Day | Ozone, ppbV |
Solar R., cal/m2 |
Wind, mph |
Temp, °F |
1973 | 5 | 1 | 41.0 | 190.0 | 7.4 | 67 |
1973 | 5 | 2 | 36.0 | 118.0 | 8.0 | 72 |
1973 | 5 | 3 | 12.0 | 149.0 | 12.6 | 74 |
1973 | 5 | 4 | 18.0 | 313.0 | 11.5 | 62 |
1973 | 5 | 5 | 14.3 | 56 | ||
1973 | 5 | 6 | 28.0 | 14.9 | 66 | |
1973 | 5 | 7 | 23.0 | 299.0 | 8.6 | 65 |
1973 | 5 | 8 | 19.0 | 99.0 | 13.8 | 59 |
1973 | 5 | 9 | 8.0 | 19.0 | 20.1 | 61 |
1973 | 5 | 10 | 194.0 | 8.6 | 69 |
= gt.tab_header(title="PFF Theme")
gt
gt.pipe(gte.gt_theme_pff)
Icons and Images
add_text_img
Points | Assists | |
---|---|---|
![]()
Josh Hart
|
1051 | 453 |
![]()
Jalen Brunson
|
1690 | 475 |
Images and data courtesy of ESPN |
import pandas as pd
from great_tables import GT, md, html
import gt_extras as gte
= pd.DataFrame(
df
{"Player": ["Josh Hart", "Jalen Brunson"],
"Points": [1051, 1690],
"Assists": [453, 475],
}
)
= gte.add_text_img(
hart_img ="Josh Hart",
text="https://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3062679.png",
img_url
)
= gte.add_text_img(
brunson_img ="Jalen Brunson",
text="https://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3934672.png",
img_url
)
"Player"] = [hart_img, brunson_img]
df[= (
gt ="Player")
GT(df, rowname_col"Images and data courtesy of [ESPN](https://www.espn.com)"))
.tab_source_note(md(
)
gt
fa_icon_repeat
World Population in 2020 | ||
Each person icon represents ~10 million people | ||
Country | Population | People |
---|---|---|
United States | 331,511,512 | |
Brazil | 213,196,304 | |
Mexico | 125,998,302 | |
France | 67,571,107 | |
Colombia | 50,930,662 | |
Poland | 37,899,070 | |
Ecuador | 17,588,595 | |
Haiti | 11,306,801 | |
Switzerland | 8,638,167 |
import pandas as pd
from great_tables import GT
from great_tables.data import countrypops
import gt_extras as gte
= (
countries_2020
countrypops"year == 2020")
.query("population", ascending=False)
.sort_values(2, 5, 10, 20, 28, 38, 65, 80, 98]]
.iloc[[
)
# Scale: 1 icon = 10 million people
def create_population_icons(population):
= max(1, round(population / 10_000_000))
icon_count
return gte.fa_icon_repeat(
="person",
name=icon_count,
repeats="cornflowerblue",
fill
)
# Prepare the data
= pd.DataFrame({
df "Country": countries_2020["country_name"],
"Population": countries_2020["population"],
"People": [create_population_icons(pop) for pop in countries_2020["population"]],
})
(
GT(df)
.tab_header(="World Population in 2020",
title="Each person icon represents ~10 million people"
subtitle
)
.fmt_number(="Population",
columns=0
decimals
) )
gt_fa_rank_change
name | 1996_2001 | 2001_2006 | 2006_2011 |
---|---|---|---|
Addington Highlands | -0.0111
|
0.0458
|
0.002
|
Adelaide Metcalfe | 0.0067
|
-0.0044
|
-0.0341
|
Adjala-Tosorontio | 0.0773
|
0.0608
|
-0.0086
|
Admaston/Bromley | -0.0046
|
-0.0382
|
0.0471
|
Ajax | 0.1447
|
0.2226
|
0.2155
|
Alberton | -0.0691
|
0.0021
|
-0.0981
|
Alfred and Plantagenet | 0.0334
|
0.0071
|
0.0626
|
Algonquin Highlands | 0.083
|
0.0816
|
0.1063
|
Alnwick/Haldimand | 0.0575
|
0.1008
|
0.0283
|
Amaranth | 0.0928
|
0.0199
|
0.0307
|
from great_tables import GT
from great_tables.data import towny
import gt_extras as gte
= towny.head(10)
mini_towny = GT(mini_towny).cols_hide(None).cols_unhide("name")
gt
= [
columns "pop_change_1996_2001_pct",
"pop_change_2001_2006_pct",
"pop_change_2006_2011_pct",
]
for col in columns:
= (
gt
gt=col, align="center")
.cols_align(columns
.cols_unhide(col)11:20]})
.cols_label({col: col[
.pipe(
gte.gt_fa_rank_change,=col,
column=[-0.01, 0.01],
neutral_range
)
)
gt
gt_fa_rating
Car | mfr | hp | trq | mpg_c | rating |
---|---|---|---|---|---|
F12Berlinetta | Ferrari | 731.0 | 509.0 | 11.0 | |
LaFerrari | Ferrari | 949.0 | 664.0 | 12.0 | |
NSX | Acura | 573.0 | 476.0 | 21.0 | |
GT-R | Nissan | 545.0 | 436.0 | 16.0 | |
Aventador | Lamborghini | 700.0 | 507.0 | 11.0 | |
Huracan | Lamborghini | 610.0 | 413.0 | 16.0 | |
Gallardo | Lamborghini | 550.0 | 398.0 | 12.0 | |
Continental GT | Bentley | 500.0 | 487.0 | 15.0 |
from random import randint
from great_tables import GT
from great_tables.data import gtcars
import gt_extras as gte
= (
gtcars_mini
gtcars8:15, ["model", "mfr", "hp", "trq", "mpg_c"]]
.loc[=[randint(1, 5) for _ in range(8)])
.assign(rating
)
= (
gt ="model")
GT(gtcars_mini, rowname_col="Car")
.tab_stubhead(label
)
="rating", name="star") gt.pipe(gte.gt_fa_rating, columns
img_header
![]()
Josh Hart
|
![]()
Jalen Brunson
|
![]()
Mikal Bridges
|
|
---|---|---|---|
Points | 1051 | 1690 | 1444 |
Rebounds | 737 | 187 | 259 |
Assists | 453 | 475 | 306 |
Blocks | 27 | 8 | 43 |
Steals | 119 | 60 | 75 |
Images and data courtesy of ESPN |
import pandas as pd
from great_tables import GT, md
import gt_extras as gte
= pd.DataFrame(
df
{"Category": ["Points", "Rebounds", "Assists", "Blocks", "Steals"],
"Hart": [1051, 737, 453, 27, 119],
"Brunson": [1690, 187, 475, 8, 60],
"Bridges": [1444, 259, 306, 43, 75],
}
)
= gte.img_header(
hart_header ="Josh Hart",
label="https://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3062679.png",
img_url
)
= gte.img_header(
brunson_header ="Jalen Brunson",
label="https://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3934672.png",
img_url
)
= gte.img_header(
bridges_header ="Mikal Bridges",
label="https://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3147657.png",
img_url
)
= (
gt ="Category")
GT(df, rowname_col"Images and data courtesy of [ESPN](https://www.espn.com)"))
.tab_source_note(md(
.cols_label(
{"Hart": hart_header,
"Brunson": brunson_header,
"Bridges": bridges_header,
}
)
)
gt
Utilities
fmt_pct_extra
name | Population Change | ||
---|---|---|---|
'96-'01 | '01-'06 | '06-'11 | |
Whitchurch-Stouffville | 11.6% | 6.7% | 54.3% |
White River | <5% | -15.3% | -27.8% |
Whitestone | 6.4% | 20.8% | -10.9% |
Whitewater | <5% | <5% | <5% |
Wilmot | 7.5% | 15.0% | 12.4% |
Windsor | 5.4% | <5% | <5% |
Wollaston | -5.6% | 7.5% | <5% |
Woodstock | <5% | 8.3% | 5.4% |
Woolwich | 5.1% | 8.0% | 17.7% |
Zorra | <5% | <5% | <5% |
from great_tables import GT
from great_tables.data import towny
import gt_extras as gte
= towny[
towny_mini
["name",
"pop_change_1996_2001_pct",
"pop_change_2001_2006_pct",
"pop_change_2006_2011_pct",
]10)
].tail(
= (
gt
GT(towny_mini)="Population Change", columns=[1, 2, 3])
.tab_spanner(label
.cols_label(="'96-'01",
pop_change_1996_2001_pct="'01-'06",
pop_change_2001_2006_pct="'06-'11",
pop_change_2006_2011_pct
)
)
gt.pipe(
gte.fmt_pct_extra,=[1, 2, 3],
columns=5,
threshold="green",
color )
gt_add_divider
name_given | Location | phone_number | Body Measurements | ||
---|---|---|---|---|---|
address | city | height_cm | weight_kg | ||
Ruth | 4299 Bobcat Drive | Baileys Crossroads | 240-783-7630 | 153 | 76.4 |
Peter | 3705 Hidden Pond Road | Red Boiling Springs | 615-699-3517 | 175 | 74.9 |
Fanette | 4200 Swick Hill Street | New Orleans | 985-205-2970 | 167 | 61.6 |
Judyta | 2287 Cherry Ridge Drive | Oakfield | 585-948-7790 | 156 | 54.5 |
Leonard | 1496 Hillhaven Drive | Los Angeles | 323-857-6576 | 177 | 113.2 |
Maymun | 4088 Barnes Avenue | Hamilton | 513-738-1936 | 172 | 88.4 |
import pandas as pd
from great_tables import GT
from great_tables.data import peeps
import gt_extras as gte
= peeps.head(6)
peeps_mini
= (
gt
GT(peeps_mini)
.cols_hide(["name_family", "postcode", "country", "country_code",
"dob", "gender", "state_prov", "email_addr",
])"Location", ["address", "city"])
.tab_spanner("Body Measurements", ["height_cm", "weight_kg"])
.tab_spanner(
)
gt.pipe(
gte.gt_add_divider,="name_given",
columns="#FFB90F",
color="double",
divider_style=8,
weight
).pipe(
gte.gt_add_divider,="phone_number",
columns="purple",
color=["right", "left"],
sides=5,
weight )
gt_duplicate_column
mfr | model | year | hp_dupe | hp |
---|---|---|---|---|
Ford | GT | 2017 | 647.0 | 647.0 |
Ferrari | 458 Speciale | 2015 | 597.0 | 597.0 |
Ferrari | 458 Spider | 2015 | 562.0 | 562.0 |
Ferrari | 458 Italia | 2014 | 562.0 | 562.0 |
Ferrari | 488 GTB | 2016 | 661.0 | 661.0 |
from great_tables import GT
from great_tables.data import gtcars
import gt_extras as gte
= gtcars[["mfr", "model", "year", "hp"]].head(5)
gtcars_mini = GT(gtcars_mini)
gt
(
gt.pipe(
gte.gt_duplicate_column,="hp",
column="year",
after
).pipe(
gte.gt_highlight_cols,"hp", "hp_dupe"],
[="tan",
fill
).pipe(
gte.gt_add_divider,=["hp_dupe"],
columns=False,
include_labels
) )
gt_merge_stack
team_abbr | team_wordmark | |
---|---|---|
NFC | ||
Cardinals
NFC West
|
ARI | ![]() |
Falcons
NFC South
|
ATL | ![]() |
Panthers
NFC South
|
CAR | ![]() |
Bears
NFC North
|
CHI | ![]() |
AFC | ||
Ravens
AFC North
|
BAL | ![]() |
Bills
AFC East
|
BUF | ![]() |
Bengals
AFC North
|
CIN | ![]() |
Browns
AFC North
|
CLE | ![]() |
import pandas as pd
from great_tables import GT
import gt_extras as gte
= pd.read_csv("../assets/teams_colors_logos.csv")
df = (df.filter(items=["team_nick", "team_abbr", "team_conf", "team_division", "team_wordmark"]).head(8))
df
= GT(df, groupname_col="team_conf", rowname_col="team_nick")
gt = gt.fmt_image(columns="team_wordmark")
gt
gt.pipe(
gte.gt_merge_stack,="team_nick",
col1="team_division",
col2 )
gt_two_column_layout
Joined Table
name_given | address |
---|---|
Ruth | 4299 Bobcat Drive |
Peter | 3705 Hidden Pond Road |
Fanette | 4200 Swick Hill Street |
Judyta | 2287 Cherry Ridge Drive |
Leonard | 1496 Hillhaven Drive |
Maymun | 4088 Barnes Avenue |
name_given | address |
---|---|
Alma | 4897 Duffy Street |
Mariana | 2016 Kovar Road |
Ning | 3892 Bel Meadow Drive |
Martin | 1850 Valley Lane |
Cendrillon | Rue de Liège 466 |
Adélaïde | Orchideeenlaan 470 |
from great_tables import GT
import gt_extras as gte
from great_tables.data import peeps
= peeps.loc[0:5, ["name_given", "address"]]
df1 = peeps.loc[6:11, ["name_given", "address"]]
df2
= GT(df1).tab_header(title="Joined Table")
gt1 = GT(df2)
gt2
=1) gte.gt_two_column_layout(gt1, gt2, table_header_from
with_hyperlink
import pandas as pd
from great_tables import GT
import gt_extras as gte
= pd.DataFrame(
df
{"name": ["Great Tables", "Plotnine", "Quarto"],
"url": [
"https://posit-dev.github.io/great-tables/",
"https://plotnine.org/",
"https://quarto.org/",
],"github_stars": [2334, 4256, 4628],
"repo_url": [
"https://github.com/posit-dev/great-tables",
"https://github.com/has2k1/plotnine",
"https://github.com/quarto-dev/quarto-cli",
],
}
)
"Package"] = [
df[
gte.with_hyperlink(name, url)for name, url in zip(df["name"], df["url"])
]
"Github Stars"] = [
df[=False)
gte.with_hyperlink(github_stars, repo_url, new_tabfor github_stars, repo_url in zip(df["github_stars"], df["repo_url"])
]
"Package", "Github Stars"]]).tab_header("Click the Links!") GT(df[[
with_tooltip
Hover for Tooltip | |
Package | Designed for |
---|---|
Great Tables | Tabling |
Plotnine | Plotting |
Quarto | Notebooking |
import pandas as pd
from great_tables import GT
import gt_extras as gte
= pd.DataFrame(
df
{"name": ["Great Tables", "Plotnine", "Quarto"],
"Description": [
"Absolutely Delightful Table-making in Python",
"A grammar of graphics for Python",
"An open-source scientific and technical publishing system",
],"Designed for": ["Tabling", "Plotting", "Notebooking"]
}
)
"Package"] = [
df[= "none")
gte.with_tooltip(name, description, color for name, description in zip(df["name"], df["Description"])
]
"Package", "Designed for"]]).tab_header("Hover for Tooltip") GT(df[[