We provide a collection of helper functions to enhance tables created with the Python package great-tables.
The functions in gt-extras are designed to make it easier to add plots, icons, color gradients, and other enhancements to your tables. We wrap up common patterns and boilerplate so you can focus on your data and presentation. It is based on the R package gtExtras, which was designed with a similar goal in mind.
How can I use it?
Install the latest release from PyPI:
$ pip install gt_extras
Now we can modify a great table with a collection of gt-extras features. From plotting, to icons, to color palettes, we’ve got quite the range of ready-to-use add-ons!
from great_tables import GTfrom great_tables.data import gtcarsimport gt_extras as gtegtcars_mini = gtcars.iloc[5:15].copy().reset_index(drop=True)gtcars_mini["efficiency"] = gtcars_mini["mpg_c"] / gtcars_mini["hp"] *100(# Start with a standard GT GT(gtcars_mini, rowname_col="model") .tab_stubhead(label="Car") .cols_hide(["drivetrain", "hp_rpm", "trq_rpm", "trim", "bdy_style", "msrp", "trsmn", "ctry_origin"]) .cols_align("center") .tab_header(title="Car Performance Review", subtitle="Using gt-extras functionality")# Add gt-extras features using gt.pipe() .pipe(gte.gt_color_box, columns=["hp", "trq"], palette=["lightblue", "darkblue"]) .pipe(gte.gt_plt_dot, category_col="mfr", data_col="efficiency", domain=[0, 0]) .pipe(gte.gt_plt_bar, columns=["mpg_c", "mpg_h"]) .pipe(gte.gt_fa_rating, columns="efficiency") .pipe(gte.gt_hulk_col_numeric, columns="year", palette="viridis") .pipe(gte.gt_theme_538))
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
And for a little comparison, here is the table before the gt-extras features were applied.
Some of the work that went into this project was featured on the great tables blog, if you choose to contribute hopefully that can give you a sense of the process!
Code of Conduct
Please note that the gt-extras project is released with a contributor code of conduct. By participating in this project you agree to abide by its terms.