Python 编码错误解决方案

Python

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 7: ordinal not in range(128)

解决方案:

import sys
reload(sys)
sys.setdefaultencoding('utf8')

当然如果非shell环境下需要给个头

#coding:utf-8

之前做 Flask的时候还需要一些奇怪的错误

如果电脑名带有中文的话也是会出错的,所以最好是英文的

pandas IO 如果有的时候遇到乱码

df.to_excel('result.xlsx',encoding="utf_8_sig")

最后附上一个小知识点

pandas 如果是日期相减 之后想求差多少天

frame["date_delta"] /= np.timedelta64(1, 'D')

Python 编码错误解决方案的更多相关文章

  1. 记一次python编码错误

    摘要: 断断续续写python一段时间了,让我说python最令我头疼的问题,莫过于编码问题.最近做大论文,使用python再次出现编码报错.错误如下: "UnicodeEncodeErro ...

  2. python编码错误

    初学python,遇到的最难忘的坑没有之一.这个问题起码困扰了我一周.在我写了一段代码之后经常遇见这样的报错. 本质原因是我用的python2,在编码流派中python2是比较奇葩的一派,不随大流.所 ...

  3. Python 编码错误的本质原因

    转载自:https://foofish.net/python-unicode-error.html 不论你是有着多年经验的 Python 老司机还是刚入门 Python 不久的新贵,你一定遇到过Uni ...

  4. python编码错误的解决办法 SyntaxError: Non-ASCII character '\xe5' in file

    [提出问题]. 在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息: SyntaxError: Non-ASCII character '\xe5' in file ******* ...

  5. Python编码错误的解决办法SyntaxError: Non-ASCII character '\xe5' in file

    [现象] 在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息: SyntaxError: Non-ASCII character '\xe5' in file ******* [原因 ...

  6. python 编码问题解决方案

    1.UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128) ...

  7. RT-thread 利用Scons 工具编译提示python编码错误解决办法

    错误信息: scons: Reading SConscript files ...UnicodeDecodeError: 'ascii' codec can't decode byte 0xbd in ...

  8. dotnet core gbk 编码错误解决方案

    .Net Core GBK解码 1.添加引用 System.Text.Encoding.CodePages 2.注册   Encoding.RegisterProvider(CodePagesEnco ...

  9. Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案

    #Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案   ##问题描述 使用Python2.7.x运行GAE时有时会报这个错误 ```py ...

随机推荐

  1. [LeetCode] 753. Cracking the Safe 破解密码

    There is a box protected by a password. The password is n digits, where each letter can be one of th ...

  2. [LeetCode] 466. Count The Repetitions 计数重复个数

    Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc&qu ...

  3. [LeetCode] 406. Queue Reconstruction by Height 根据高度重建队列

    Suppose you have a random list of people standing in a queue. Each person is described by a pair of ...

  4. Windows10 WSL下 龙芯3A 交叉编译环境搭建

    记个流水账避免事后忘记怎么搭建的 - - 环境 Key Value 系统 Windows10 WSL系统 Ubuntu 下载工具链 http://www.loongnix.org/index.php/ ...

  5. [原创]A/B测试系统调研思维导图

    [原创]A/B测试系统调研思维导图

  6. Spring 源码分析之AbstractApplicationContext源码分析

    首先我觉得分析ApplicationContext必须从它的实现类开始进行分析,AbstractApplicationContext我觉得是一个不错的选择,那我们就从这里开始逐一分析吧,首先我自己手画 ...

  7. react 16 Hooks渲染流程

    useState react对useState进行了封装,调用了mountState. function useState<S>( initialState: (() => S) | ...

  8. SpringBoot2配置prometheus浏览器访问404

    背景:SpringBoot2的项目要配置 actuator + prometheus的健康检查,按照教程配置好之后再浏览器测试 http://localhost:port/prometheus 后40 ...

  9. python 多线程剖析

    先来看个栗子: 下面来看一下I/O秘籍型的线程,举个栗子——爬虫,下面是爬下来的图片用4个线程去写文件 #!/usr/bin/env python # -*- coding:utf-8 -*- imp ...

  10. Ajax 跨域请求,Chrome 无法显示 Set-Cookie

    在使用 Ajax 进行跨域请求时,前后端均已设置 withCredentials = true,但 Chrome 前端响应无法显示 Set-Cookie. 一开始以为 Cookie 并没有设置成功,但 ...