Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何避免UnicodeDecodeError读取此csv文件?_Python_Pandas_Csv_Dataframe - Fatal编程技术网

Python 如何避免UnicodeDecodeError读取此csv文件?

Python 如何避免UnicodeDecodeError读取此csv文件?,python,pandas,csv,dataframe,Python,Pandas,Csv,Dataframe,我有一个csv文件,数据如下: 文本值 RT@AmericanHot我们结束了。htt…A RT@votevets:Hertha Berlin German#德甲世界。… RT@votevets:Hertha Berlin球员#世界…B RT@HerthaBSC_EN:赫塔BSC永远屹立… RT@johanbakerr:没有奏国歌 当我把csv文件读为 df = pd.read_csv('Book1.csv') 这给了我以下的错误。我正在使用python 3.6。请帮忙 UnicodeDec

我有一个csv文件,数据如下:

文本值
RT@AmericanHot我们结束了。htt…A
RT@votevets:Hertha Berlin German#德甲世界。…
RT@votevets:Hertha Berlin球员#世界…B
RT@HerthaBSC_EN:赫塔BSC永远屹立…
RT@johanbakerr:没有奏国歌
当我把csv文件读为

df = pd.read_csv('Book1.csv')
这给了我以下的错误。我正在使用python 3.6。请帮忙

UnicodeDecodeError:“utf-8”编解码器无法解码位置33中的字节0x85:无效的开始字节
试试看

试一试


您的文件未使用UTF-8编码。您需要找出实际的编码是什么。或者尝试猜测(如cp1252),看看会发生什么您的文件未使用UTF-8编码。您需要找出实际的编码是什么。或者尝试猜测(如cp1252),看看会发生什么
 df=pd.read_csv('Book1.csv',dtype='unicode')
  df=pd.read_csv('Book1.csv',dtype='unicode',encoding = "ISO-8859-1")