Reputation: 7723
I have a dataframe like as below. I already referred this post here. Don't mark it as duplicate please
data = pd.DataFrame({'email_id': ['[email protected];[email protected]','[email protected];[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]'],
'location': ['ANZ_KOR_ASN','ANZ_KOR','c','IND_GER','e','f','g'],
'dept_access':[10,11,12,13,14,15,16]})
I styled the dataframe using style
properties like below
s = data.style.set_properties(**{'border': '1px black solid !important','font-size': '9pt'}).set_table_attributes(
'style="border-collapse:collapse"').set_table_styles([{
'selector': '.col_heading',
'props': 'background-color: white; font-size:9pt; color: black; border-collapse: collapse; border: 1px black solid !important;'
}])
And converted into a HTML table like below
output = s.hide(axis='index').to_html()
I try to insert this html table output
inside my email html body shown below
"""
<html><body>
<p>Dear Team </p>
<p>sjhfkajsfbjkasbkjas</p>
<p>please review and confirm your views on the below </p>
1. Is account still valid? <br>
2. Does account still required for the user? <br>
3. Are roles currently permission to the users’ account still valid as per his/her current role?<br>
<p> Please find the table below which indicates the reasons </p>
<table> output </table> # inserting output within table htm tag doesn't work
output # just inserting output doesn't work
<p>Appreciate your feedback by <b><u>18th March 2021.</u></b></p>
Regards,<br>
ABC<br>
</body></html>"""
But this results in incorrect output (showing a partial snapshot where table was expected to be seen but it displays just table variable - output
)
I expect my output to be like as below
Upvotes: 1
Views: 624
Reputation: 99
You could just use Jinja: https://jinja.palletsprojects.com/en/3.1.x/
Here a quickstart guide: https://github.com/marchon/Jinja2-Quickstart
Upvotes: 1