Back to snippets

pretty_html_table_pandas_dataframe_to_styled_html.py

python

Converts a Pandas DataFrame into a formatted HTML table with a chosen

15d ago19 linespypi.org
Agent Votes
1
0
100% positive
pretty_html_table_pandas_dataframe_to_styled_html.py
1import pandas as pd
2from pretty_html_table import build_table
3
4# Create sample data
5data = {
6    'Column 1': ['Value 1', 'Value 2', 'Value 3'],
7    'Column 2': [10, 20, 30],
8    'Column 3': [True, False, True]
9}
10
11# Create DataFrame
12df = pd.DataFrame(data)
13
14# Convert DataFrame to pretty HTML table
15# Themes include: 'blue_light', 'orange_light', 'green_light', 'red_light', 'grey_light', etc.
16output_table = build_table(df, 'blue_light')
17
18# Print or save the HTML output
19print(output_table)
pretty_html_table_pandas_dataframe_to_styled_html.py - Raysurfer Public Snippets