普通网友 2019-08-29 16:05 采纳率: 100%
浏览 4298
已采纳

UnicodeEncodeError: 'gbk' codec can't encode character '\xa9' in position 1140

问题如下图所示
图片说明

def df_to_html(df, out_fname, detail=0, bbox=None):
c_lng, c_lat = df.iloc[0]['Longitude'], df.iloc[0]['Latitude']
html = const_prefix % (c_lat, c_lng)
for i in range(len(df)):
lng, lat = df.iloc[i]['Longitude'], df.iloc[i]['Latitude']
marker = '[%s, %s]' % (lat, lng)
if bbox is None or (bbox is not None and bbox[0][0] <= lat <= bbox[1][0] and bbox[0][1] <= lng <= bbox[1][1]):
if detail:
html += const_circle_pop % (marker, 'red', 2, i)
else:
html += const_circle % (marker, 'red', 2)
html += const_suffix
with open(out_fname, 'w') as o_file:
o_file.write(html)


  • 写回答

3条回答 默认 最新

  • searchspace 2019-08-31 14:06
    关注

    使用encoding='gb18030' 打开要写的文件就可以。'\xa9'是一个gb字符。图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?