I keep getting:
UnicodeEncodeError: \'ascii\' codec can\'t encode characters in position 265-266: ordinal not in range(128)
when I try:
The issue is actually in using df.to_html("mypage.html") to save the HTML to a file directly. If instead you write the file yourself, you can avoid this encoding bug with pandas.
html = df.to_html()
with open("mypage.html", "w", encoding="utf-8") as file:
file.write(html)
You may also need to specify the character set in the head of the HTML for it to show up properly on certain browsers (HTML5 has UTF-8 as default):
This was the only method that worked for me out of the several I've seen.