指定编码utf-8时,为什么熊猫read_csv有unicode错误?

时间:2018-08-14 10:20:46

标签: python pandas

在Jupyter 5.000笔记本中执行以下Python 3.6代码时:

import pandas as pd
file = "C:\users\frogf\MSDS7333\data\HIGGS.csv"
data=pd.read_csv(file,nrows=N,header=None,encoding = "utf-8")

它给出了错误:

 File "<ipython-input-5-204f62a7e8b4>", line 2
    file = "C:\users\frogf\MSDS7333\data\HIGGS.csv"
          ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX escape

1 个答案:

答案 0 :(得分:1)

以原始字符串打开文件。试试:

import pandas as pd
data=pd.read_csv(r"C:\users\frogf\MSDS7333\data\HIGGS.csv",nrows=10,header=None,encoding = "utf-8")
相关问题