Data is only as valuable as its presentation. While Python developers often rely on libraries like Pandas and Polars to manipulate and analyze data, crafting visually compelling tables for reports, dashboards, and presentations remains a challenge. Many settle for df.head()
and standard DataFrame outputs, but what if tables could be as expressive as charts?
Enter Great Tables, an advanced Python library that transforms tabular data into structured, formatted, and visually engaging representations. Whether you are a data scientist, developer, or analyst, Great Tables helps you craft stunning tables with interactive elements, nano plots, images, and advanced formatting options.
In this blog post, we’ll explore:
- The need for better table design
- The capabilities of Great Tables
- How to structure, format, and style tables
- Advanced features like nano plots and column spanners
- Exporting tables to HTML, PDFs, and LaTeX
- How to start using Great Tables in your projects
If you’ve ever struggled with making your tables more insightful, this guide is for you.
The Need for Better Table Design
Data presentation is as important as analysis. Here’s why:
- Raw tables can be overwhelming – A sea of numbers is hard to interpret at a glance.
- Excel dominates – Many users rely on Excel for formatting, even when their data workflow is in Python.
- Charts are not always enough – Some insights need precise tabular representations.
- Tables lack visual clarity – Key insights get lost in basic table outputs.
Python’s standard options (like Pandas’ .to_html()
or .to_csv()
) do not offer the styling, structure, and interactive features that Great Tables provides.
Let’s see how Great Tables revolutionizes tabular data representation.
Setting Up Great Tables
Before we dive into examples, install the library using:
pip install great-tables
Next, import it into your Python script:
import great_tables as gt
import polars as pl # Recommended for enhanced selection
Now, let’s start building great tables!
Building a Basic Table with Great Tables
To get started, let’s create a simple sales report using Pandas and Great Tables.
import pandas as pd
import great_tables as gt
# Sample data
data = {
"Product": ["Laptop", "Smartphone", "Tablet", "Monitor", "Keyboard"],
"Units Sold": [120, 350, 90, 180, 250],
"Revenue ($)": [120000, 175000, 45000, 54000, 25000],
}
df = pd.DataFrame(data)
# Create a Great Table
table = gt.GreatTable(df)
table.show()
This outputs a clean, structured table in a Jupyter Notebook or browser.
Advanced Table Structuring and Formatting
Great Tables provides several powerful formatting options:
1. Adding Titles and Subtitles
table = (
gt.GreatTable(df)
.tab_header("📊 Sales Report", "Q1 2025")
)
table.show()
This adds a clear title and subtitle, improving readability.
2. Formatting Currency and Numbers
table = (
gt.GreatTable(df)
.fmt_currency("Revenue ($)", prefix="$")
.fmt_integer("Units Sold")
)
table.show()
Numbers are now formatted properly, just like in Excel.
3. Highlighting Maximum and Minimum Values
table = (
gt.GreatTable(df)
.tab_header("📊 Sales Report", "Q1 2025")
.fmt_currency("Revenue ($)", prefix="$")
.fmt_integer("Units Sold")
.highlight_max("Revenue ($)", color="green")
.highlight_min("Revenue ($)", color="red")
)
table.show()
Now, the highest revenue is highlighted in green and the lowest in red.
4. Grouping Columns with Spanners
table = (
gt.GreatTable(df)
.tab_header("📊 Sales Report", "Q1 2025")
.fmt_currency("Revenue ($)", prefix="$")
.tab_spanner("Financial Data", ["Units Sold", "Revenue ($)"])
)
table.show()
Spanners group related columns together, making interpretation easier.
Enhancing Tables with Interactive Elements
1. Adding Nano Plots
Nano plots are tiny visualizations inside tables, perfect for time-series data.
import numpy as np
# Generate random sales data for each month
df["Monthly Sales"] = [np.random.randint(50, 500, 6).tolist() for _ in range(len(df))]
table = (
gt.GreatTable(df)
.tab_header("📊 Sales Report", "Q1 2025")
.fmt_currency("Revenue ($)", prefix="$")
.tab_spanner("Financial Data", ["Units Sold", "Revenue ($)"])
.fmt_nanoplot("Monthly Sales", kind="bar")
)
table.show()
Each row now has a tiny bar chart showing sales trends!
Exporting Tables to Different Formats
1. Saving as HTML
table.save("sales_report.html")
2. Exporting to LaTeX (for academic papers)
table.to_latex("sales_report.tex")
3. Saving as an Image or PDF
table.save("sales_report.png")
table.save("sales_report.pdf")
Exporting tables to multiple formats makes them easy to use in reports, websites, and publications.
Great Tables vs. Other Table Libraries
Feature | Pandas | Great Tables |
---|---|---|
Basic Tables | ✅ | ✅ |
Styled Formatting | ❌ | ✅ |
Column Grouping | ❌ | ✅ |
Conditional Formatting | ❌ | ✅ |
Interactive Plots | ❌ | ✅ |
Markdown Support | ❌ | ✅ |
Export to PDF/LaTeX | ❌ | ✅ |
Great Tables significantly extends what you can do with tables in Python.
Use Cases for Great Tables
- 📊 Business Reports – Generate polished sales reports with highlights.
- 🏆 Sports Analytics – Create interactive tables with team performance stats.
- 🎓 Research Papers – Export tables to LaTeX for publications.
- 🏢 Corporate Dashboards – Embed formatted tables in executive presentations.
Wherever you need structured, formatted, and interactive tables, Great Tables is the answer.
Conclusion
Great Tables brings a new level of sophistication to data presentation in Python. Whether you’re working with business reports, research papers, or interactive dashboards, it provides:
✅ Beautifully formatted tables
✅ Advanced features like nano plots and column spanners
✅ Export options for HTML, PDFs, and LaTeX
✅ Seamless integration with Polars and Pandas
Upgrade your data storytelling today by installing Great Tables and experimenting with your datasets.
Try it now: Install with
pip install great-tables
and start crafting beautiful tables.
Further Reading
- 📖 Great Tables Documentation
- 🐍 Talk Python Podcast on Great Tables
- 🔢 Polars – A Faster Alternative to Pandas
Leave a Reply