How to export DataFrame to Html with utf-8 encoding?

后端 未结 4 1436
南笙
南笙 2021-01-05 05:39

I keep getting:

UnicodeEncodeError: \'ascii\' codec can\'t encode characters in position 265-266: ordinal not in range(128)

when I try:

4条回答
  •  再見小時候
    2021-01-05 06:01

    The way it worked for me:

    html = df.to_html()
    
    with open("dataframe.html", "w", encoding="utf-8") as file:
        file.writelines('\n')
        file.write(html)
    

提交回复
热议问题