admin管理员组文章数量:1295873
I am converting a pandas dataframe to HTML table but unable to figure out why the HTML table does not retain the conditional format. When I save the dataframe to excel, i do see the formatting as expected. Any insight is appreciated. Thank You.
fiveg = pd.read_csv('5g.csv', engine="python", encoding="UTF-8")
def highlights(row):
if row['Col A'] < 1:
return ['background-color: yellow'] * len(row)
else:
return [''] * len(row)
fiveg_style = fiveg.style.apply(highlights, axis=1)
## The appropriate rows are highlighted in yellow
fiveg_style.to_excel('test.xlsx', engine='openpyxl', index=False)
# the html table is created but the appropriate rows are NOT higlighted.
html_table_fiveg = fiveg_style.to_html(index=False)
FROM = 'XXX'
TO = "YYY"
SUBJECT = "ABC"
styled_HTML = f"""\
<html>
<head>
<style>
table {{
width: 100%;
border-collapse: collapse;
font-size: 10px;
}}
th, td {{
border: 1px solid black;
padding: 8px;
text-align: justify;
}}
th {{
background-color: #F0F8FF;
}}
</style>
</head>
<body>
<p><b>5G</b><br>
{html_table_fiveg}
</p>
</body>
</html>
"""
本文标签: Pandas dataframe to HTML table (Gmail Body)Stack Overflow
版权声明:本文标题:Pandas dataframe to HTML table (Gmail Body) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741624212a2388991.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论