现在有文件data.csv 文件编码格式为:ANSI

data.csv

1|1|1|北京市
2|1|2|天津市
3|1|3|上海市
4|1|4|重庆市
5|1|5|石家庄市
6|2|5|唐山市
7|3|5|秦皇岛市
8|4|5|邯郸市
9|5|5|邢台市
10|6|5|保定市
11|7|5|张家口市
12|8|5|承德市
13|9|5|沧州市
14|10|5|廊坊市
15|11|5|衡水市
16|1|6|太原市
17|2|6|大同市

在python控制台输入以下代码:

>>> import pandas as pd
>>> df = pd.read_excel('C:\\Users\\Thinkpad\\Desktop\\data.csv')
>>> df

报错如下:

这样看来,是编码造成的问题,只需要在读取的时候指定编码即可。

解决办法

指定了编码,正常读取了

【Python】读取cvs文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 6: invalid start byte的更多相关文章

  1. python读取txt文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x8e in position 8: illegal multibyte sequence

    python读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x8e in position 8: illegal multibyte ...

  2. python3 读取dbf文件报错 UnicodeDecodeError: 'gbk' codec can't decode

    在读取dbf文件时由于编码问题报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xb5 in position 49: incomplete ...

  3. python读取xml文件报错ValueError: multi-byte encodings are not supported

    1.在使用python对xml文件进行读取时,提示ValueError: multi-byte encodings are not supported 很多贴子上说把xml的编码格式改为,就可以正常执 ...

  4. 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence

    python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte ...

  5. 解决Requests中文乱码【有用】,读取htm文件 读取txt文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0

    打开这个网址https://blog.csdn.net/chaowanghn/article/details/54889835 python在open读取txt文件时,出现UnicodeDecodeE ...

  6. Pandas读取文件报错UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

    pandas读取文件时报UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start by ...

  7. python 读取配置文件总是报错 configparser.NoSectionError: No section:

    本文为作者原创,禁止转载,违者必究法律责任!!! python 读取配置文件总是报错 configparser.NoSectionError: No section: 无论是 python2的版本,还 ...

  8. 文件读取错误UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 884: invalid start byte

    参考: https://segmentfault.com/q/1010000004268196/a-1020000004269556 ubuntu下Python3使用open('filename', ...

  9. python3 报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 201: invalid continuation byte

    代码: # -*- coding:utf-8 -*- from urllib import request resp = request.urlopen('http://www.xxx.com') p ...

随机推荐

  1. 【Luogu】P3320寻宝游戏(Splay)

    题目链接 其实这题用Set就完事了但我不会Set 智商-=inf 求虚树上所有边权和的两倍. 具体方式就是splay把所有在虚树上的点存一下,(按照DFS序排序的)每次插入/删除会更新前驱和它.后继和 ...

  2. 数组洗牌算法-shuffle

    数组洗牌,最近直接的想法是从数组随机取出一个元素,放到另一个数组中,但是这样取出的元素会有重复,必须采取一定的方法保证: 1. 元素不能重复2. 元素被抽取的概率相等,即随机性 数组洗牌经典算法有两种 ...

  3. JS 改变鼠标样式

    此片记录如何改变鼠标样式: document.body.style.cursor = "url(resource/pic/icons/magnifier3.cur) 12 12,crossh ...

  4. [LeetCode] Path Sum II 深度搜索

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...

  5. mysql 更新数据

    set @num= 1000;update table set a= @num:=@num+1; set @date=now();UPDATE Orders t SET t.CreateTime = ...

  6. mysql中文乱码的解决方法

    MySQL的字符集支持(Character Set Support)有两个方面: 字符集(Character set)和排序方式(Collation).对于字符集的支持细化到四个层次: 服务器(ser ...

  7. Android Studio中删除所有的断点

    直接上图,我相信你们能看的懂,骚年们. 第1个图:Run–>>View Breakpoints.. 第2个图:现在可以看到所有的断点了,在左侧栏全选,然后点"-",就全 ...

  8. C++ primer分章节快速回顾

    第三章: 1,sozeof(int): int n_int=INT_MAX; sizeof n_int;(对变量括号可选) 2,#include<climits>包含一些类型的最大值3,c ...

  9. 利用Jdk 6260652 Bug解析Arrays.asList

    在java.util.ArrayList源码中: c.toArray might (incorrectly) not return Object[] (see 6260652) 产生疑惑: 附上Jav ...

  10. asp.net站点从2003服务器迁移到2008服务器出现定义了重复的“system.web.extensions/scripting/scriptResourceHandler”节的问题解决

    解决方法: 1.从4.0降到2.0. 2.直接删除整个节点,如下: