0
0
Data Analysis Pythondata~30 mins

Report generation (notebooks to HTML/PDF) in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Report generation (notebooks to HTML/PDF)
📖 Scenario: You work as a data analyst. Your manager wants a clean report of your analysis. You will create a simple data summary and then generate a report from it. The report will be saved as an HTML file, which can also be converted to PDF later.
🎯 Goal: Build a small Python script that creates a data summary dictionary, sets a report title, generates an HTML report string using the data, and finally saves the report to an HTML file.
📋 What You'll Learn
Create a dictionary with data summary values
Create a variable for the report title
Generate an HTML string using the data and title
Save the HTML string to a file named 'report.html'
Print a confirmation message with the file name
💡 Why This Matters
🌍 Real World
Data analysts often need to share their findings in easy-to-read reports. Generating HTML reports is a simple way to create visually clear summaries that anyone can open in a web browser.
💼 Career
Knowing how to automate report generation saves time and ensures consistent presentation of data insights, a valuable skill for data analysts and scientists.
Progress0 / 4 steps
1
Create the data summary dictionary
Create a dictionary called data_summary with these exact entries: 'total_sales': 1500, 'total_customers': 300, and 'average_sale': 5.0.
Data Analysis Python
Hint

Use curly braces {} to create a dictionary. Separate keys and values with colons.

2
Set the report title
Create a variable called report_title and set it to the string 'Monthly Sales Report'.
Data Analysis Python
Hint

Use an equals sign = to assign the string to the variable.

3
Generate the HTML report string
Create a variable called html_report that stores a string with HTML content. Use an f-string to include report_title inside an <h1> tag and the values from data_summary inside <p> tags. The HTML should look like this exactly:
<h1>Monthly Sales Report</h1>
<p>Total Sales: 1500</p>
<p>Total Customers: 300</p>
<p>Average Sale: 5.0</p>
Data Analysis Python
Hint

Use an f-string with triple quotes or escaped newlines \n to format the HTML string.

4
Save the HTML report and print confirmation
Write the html_report string to a file named 'report.html' using open with mode 'w'. Then print the exact message "Report saved to report.html".
Data Analysis Python
Hint

Use with open('report.html', 'w') as file: and file.write(html_report). Then use print for the message.