我下载了this dataset并将其存储在名为AutomobileDataset
的文件夹中。
我使用以下方式交叉检查工作目录:
import pandas as pd
import numpy as np
import os
os.chdir("/Users/madan/Desktop/ML/Datasets/AutomobileDataset")
os.getcwd()
输出:
'/Users/madan/Desktop/ML/Datasets/AutomobileDataset'
然后我尝试使用pandas读取文件:
import pandas as pd
import numpy as np
import os
os.chdir("/Users/madan/Desktop/ML/Datasets/AutomobileDataset")
os.getcwd()
automobile_data = pd.read_csv("AutomobileDataset.txt", sep = ',',
header = None, na_values = '?')
automobile_data.head()
输出:
---------------------------------------------------------------------------
ParserError: Error tokenizing data. C error: Expected 1 fields in line 2, saw 26
有人请帮助我,我不知道我在哪里犯了错误。
答案 0 :(得分:0)
可以尝试一下!
import os
# Read in a plain text file
with open(os.path.join("c:user/xxx/xx", "xxx.txt"), "r") as f:
text = f.read()
print(text)