Pretty HTML Table for Pandas DataFrames

0.9.16 · maintenance · verified Sat Apr 11

pretty-html-table (v0.9.16) is a Python library designed to convert pandas DataFrames into aesthetically pleasing HTML tables, primarily for use in email reports. It offers 12 different color themes and formats HTML at the DataFrame row level to ensure broad compatibility across various email providers, avoiding common CSS rendering issues. The library is currently in maintenance mode with infrequent releases, with the last significant update in April 2022.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a pandas DataFrame and then convert it into a styled HTML table using `build_table`. The resulting HTML string can be printed, saved to a file, or embedded directly into an email body.

import pandas as pd
from pretty_html_table import build_table

# Create a sample pandas DataFrame
data = {
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [24, 27, 22],
    'City': ['New York', 'Los Angeles', 'Chicago']
}
df = pd.DataFrame(data)

# Convert the DataFrame to a pretty HTML table with a 'blue_light' theme
html_table = build_table(df, 'blue_light', width='auto', font_size='medium', text_align='left')

# Print the HTML table (for demonstration)
print(html_table)

# Optionally, save to an HTML file
# with open('pretty_table.html', 'w') as f:
#    f.write(html_table)
# print("HTML table saved to pretty_table.html")

view raw JSON →