1

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)

enter image description here

I expect my output to be like as below

enter image description here

2
  • 1
    Replace beginning """ by f""" and output by {output}. Commented Jul 29, 2022 at 10:02
  • @MichaelButscher - This worked like a charm. would you mind writing it as an answer for the benefit of others? Commented Jul 31, 2022 at 8:28

1 Answer 1

1

You could just use Jinja: https://jinja.palletsprojects.com/en/3.1.x/

Here a quickstart guide: https://github.com/marchon/Jinja2-Quickstart

Sign up to request clarification or add additional context in comments.

1 Comment

thanks. good to know but for my problem, the above comment by @Michael Butscher was simple to implement and it worked well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.