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

后端 未结 4 1435
南笙
南笙 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:20

    Your problem is in other code. Your sample code has a Unicode string that has been mis-decoded as latin1, Windows-1252, or similar, since it has UTF-8 sequences in it. Here I undo the bad decoding and redecode as UTF-8, but you'll want to find where the wrong decode is being performed:

    >>> s = u'Rue du Gu\xc3\xa9, 78120 Sonchamp'
    >>> s.encode('latin1').decode('utf8')
    u'Rue du Gu\xe9, 78120 Sonchamp'
    >>> print(s.encode('latin1').decode('utf8'))
    Rue du Gué, 78120 Sonchamp
    

提交回复
热议问题