@[salmon_gs]pandas.read_csv() 报错 OSError: Initializing from file failed的解决办法
错误1
在这里插入代码片import pandas as pdpath = ('Advertising.csv') data = pd.read_csv(path)print(data)
运行后的输出结果是:
FileNotFoundError: File b’Advertising.csv’ does not exist
错误2
在这里插入代码片import pandas as pdpath = ('F:\(新版本)邹博_机器学习\9.回归实践\9.Regression\Advertising.csv')data = pd.read_csv('path')# TV、Radio、Newspaper、Salesprint(data)
运行后的输出结果是:
FileNotFoundError: File b’path’ does not exist
此处介绍一种十分简单有效的方法:
在这里插入代码片import pandas as pddata = pd.read_csv(open('F:\\9.Regression\\Advertising.csv')print(data)
这个时候就会显示正常找到文件了
Unnamed: 0 TV Radio Newspaper Sales
0 1 230.1 37.8 69.2 22.1
1 2 44.5 39.3 45.1 10.4
2 3 17.2 45.9 69.3 9.3
3 4 151.5 41.3 58.5 18.5
4 5 180.8 10.8 58.4 12.9
…