- from pretty_html_table import build_table
- import pandas as pd
- import seaborn as sns
- from weasyprint import CSS
- from weasyprint import HTML
- import matplotlib.pyplot as plt
- df = pd.read_csv('https://raw.githubusercontent.com/fati8999-tech/Data-visualization-with-Python-Using-Seaborn-and-Plotly_-GDP-per-Capita-Life-Expectency-Dataset/master/2019.csv')
- #Change colors as appropriate: blue_light, blue_dark, grey_light, grey_dark, orange_light, orange_dark, yellow_light, yellow_dark, green_light, green_dark, red_light, red_dark
- output = build_table(df, 'green_light', font_size='medium', font_family='Open Sans, sans-serif', text_align='left', width='auto', index=False, even_color='black', even_bg_color='white')
- #Let's create an image and attach it to HTML
- plt.style.use('ggplot')
- sns.pairplot(df)
- plt.savefig("email_plots.png")
- with open("email_report.html","w+") as file:
- file.write(output)
- file.write("<img src='email_plots.png'/>")
- #HTML(string=output).write_pdf("email_report.pdf")
- HTML(string=output).write_pdf("email_report.pdf", stylesheets=[CSS(string='@page { size: landscape }')])
-
- Active Topics
-
-
- by Eli 21 hours ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 326 Views 32506
- by Eli 2 days ago Russia Invades Ukraine View the latest post Replies 662 Views 233381
- by Eli 2 days ago PySpark for Large Data Processing View the latest post Replies 1 Views 5015
- by Eli 4 days ago Re: What is in Your Mind? View the latest post Replies 700 Views 298160
- by Eli 1 week ago President Museveni's Speech During International Development Association (IDA) Summit View the latest post Replies 1 Views 257
- by Eli 1 week ago From Simple Linear Regression Analysis to Covariance & Correlation to Independent Determinant, and R-Squared View the latest post Replies 11 Views 24749
- by Eli 1 week ago Collection of Greatest Christian Hymns of all Times View the latest post Replies 34 Views 65737
- by Eli 1 week ago Pondering Big Cosmology Questions Through Lectures and Dialogues View the latest post Replies 34 Views 57975
- by Eli 1 week ago Programmatically Manipulate Files: Renaming, Reading, Writing, Deleting, and Moving Files Between Folders View the latest post Replies 7 Views 14278
- by Eli 2 weeks ago Iran Launches Retaliatory Attack Against Israel, and Israel Retaliates by Attacking Iranian Isfahan Millitary Base View the latest post Replies 28 Views 15750
-
Generate Beautiful HTML and PDF Reports with Pretty HTML Table and WeasyPrint
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5378
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Pretty-HTML-Table and WeasyPrint are Python packages that can be used in combination to generate pretty HTML and PDF reports. A while ago, we showed how to automate reports with Pandas and Python and save the resulting Pandas DataFrame to HTML, and how to generate PDF Reports with Pandas, Jinja and WeasyPrint. Today, we present the Python code below that illustrates the combined power of pretty_html_table and WeasyPrint to generate beautiful HTML and PDF reports using the global 2019 GDP Per Capita, Life Expectancy, and other Social Factors Dataset featured here.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
-
- Information
-
Who is online
Users browsing this forum: No registered users and 4 guests