在python中访问csv文件

时间:2018-11-23 09:34:18

标签: python pandas csv

import pandas as pd
csv_path="D:/arun/datasets/US Presidential Data.csv"
data=pd.read_csv(csv_path)

它工作正常,但是以下代码出现此错误:

import pandas as pd
csv_path="D:/arun/textmining/r files/twitter_data_sets/GST/GST-28-08-2017/10-10-2017.csv"
data=pd.read_csv(csv_path)

UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-3-a90c76559f26> in <module>()
      1 import pandas as pd
      2 csv_path="D:/arun/textmining/r files/twitter_data_sets/GST/GST-28-08-2017/10-10-2017.csv"
----> 3 data=pd.read_csv(csv_path)

2 个答案:

答案 0 :(得分:0)

这是一个编码错误。希望utf8可以解决。 尝试

import pandas as pd
csv_path="D:/arun/datasets/US Presidential Data.csv"
data=pd.read_csv(csv_path,encoding='utf-8')

答案 1 :(得分:0)

尝试一下:

data = pd.read_csv(csv_path, encoding = "ISO-8859-1")

data = pd.read_csv(csv_path, encoding = "utf-8")