Skip to content
Advertisement

how to Send dataframe as html table with font styling based on text value as a email attachment

I have a dataframe, In that if the value is starting with letter “A” i’m styling it in red color, now i need to send it as html table in mail but when i execute it its coming without that styling, below is the code i tried please help. please check the image for df style

JavaScript

enter image description here

Advertisement

Answer

EDIT:

I found you can assign styled dataframe to variable and use .to_html() on this dataframe.

JavaScript

OLD ANSWER:

df.to_html() always gives HTML without styles.

You may add some parameters in to_html(....) to change something. See doc for to_html().

You may use formatters to convert value into <div style="color: red">value</div>. It may need escape=False to put it as HTML in table.

JavaScript

Every column need own formatter so I repeated it 4 times in list.

Because email is not important in this problem so I skip it and I save data in file index.html and I use webbrowser to show it automatically in browser.

JavaScript

Result:

JavaScript

enter image description here


For more complex table you may have to format it on your own (using for-loops to work with every row and column separatelly).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement