<div>
from jinja2 import Template
import pandas as pd
# Step 1: Create DataFrames
df1 = pd.DataFrame({'prior': [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]})
df1['likelihood'] = ''
df1['marginal_likelihood_i_think'] = ''
df1['posterior'] = ''
# Calculate totals
totals = df1.sum().to_frame().T
totals.index = ['Total']
# Append totals to the DataFrame
df1 = pd.concat([df1, totals])
#Functions
def highlight_total_row(row):
if row.name == "Total":
return ['font-weight: bold; border-top: 2px solid black;' for _ in row]
return ['' for _ in row]
def hide_cells(row):
styles = ['' for _ in row]
if row.name == "Total":
# Hide column "B" in total row
styles[row.index.get_loc("likelihood")] = "color: transparent;"
styles[row.index.get_loc("prior")] = "color: transparent;"
return styles
styled = df1.style.apply(highlight_total_row, axis=1).apply(hide_cells, axis=1)
html = styled.to_html(index = False)
# Step 2: Define HTML Template
html_template = """
<h2>DataFrame 1</h2>
"""
# Step 3: Render HTML
template = Template(html_template)
html_output = template.render(html=html)
# Step 4: Save or Display HTML
with open('report.html', 'w') as f:
f.write(html_output)
</div>