honor0301 2019-08-29 16:05 采纳率: 100%
浏览 4290
已采纳

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条)

报告相同问题?

悬赏问题

  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机