You can try to do this in two ways:
With set_table_styles
from pandas.DataFrame.style
:
import pandas as pd import numpy as np
Or with .to_html
:
df_html_output = df.to_html(na_rep = "", index = False).replace('<th>','<th style = "background-color: red">') html.append(df_html_output) body = '\r\n\n<br>'.join('%s'%item for item in html) msg.attach(MIMEText(body, 'html'))
The second option provides the ability to delete the index column during export ( to_html
) without having to make too many t26 tweaks; therefore, it may be more suitable for your needs.
Hope this is helpful.
Abdou source share