I too was trying to format a dataframe something like the to_html function but with changes to font and color. Most of the Google found examples use the built in pandas styler functions for their examples, but I needed something simpler. The code that I ended up with was:
df = pd.DataFrame(np.random.randn(15).reshape(5,3))
print(df)
df_styled = df.style.format('{:,.2f}').set_properties(**{
'font': 'Arial', 'color': 'red', 'text-align': 'center'})
df_styled.set_table_styles([{'props': [('background-color', 'MintCream'), ('color', 'blue'), ('font', 'Arial'), ('font-weight', 'bold')]}])
df_styled.set_table_attributes('border="1"')
with open('test.html', 'w') as f:
f.write(df_styled.render())
Since I am relatively new to python and pandas I originally thought that the styler was added to the original dataframe. I now understand that the df.style..... returns a styled dataframe object which can handle further property and attribute changes before finally being rendered. In this sample I rendered the styled dataframe to a file which can then be opened with a browser to see the result. In my actual application I rendered the styled dataframe to a string object which was then sent in and email as a html mime type as the OP originally wanted.