这是我的代码:
import matplotlib.pyplot as plt
import pandas as pd
import pylab as pl
import numpy as np
df = pd.read_csv("FuelConsumption.csv")
df.head()
并且发生错误:
Traceback (most recent call last):
File "F:/python/machine learning/regression.py", line 8, in <module>
df = pd.read_csv("FuelConsumption.csv",engine = 'python')
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 686, in read_csv
return _read(filepath_or_buffer, kwds)
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 452, in _read
parser = TextFileReader(fp_or_buf, **kwds)
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 946, in __init__
self._make_engine(self.engine)
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 1189, in _make_engine
self._engine = klass(self.f, **self.options)
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\pandas\io\parsers.py", line 2382, in __init__
f, handles = get_handle(
File "C:\Users\HP\AppData\Roaming\Python\Python38\site-packages\pandas\io\common.py", line 496, in get_handle
f = open(path_or_buf, mode, errors="replace", newline="")
FileNotFoundError: [Errno 2] No such file or directory: 'FuelConsumption.csv'
我确定我已经下载了csv,但仍然无法正常工作 谁能帮我吗?
答案 0 :(得分:1)
文件路径是read_csv方法的主要参数。您应该指定csv文件的路径,如果python文件和csv文件都不在同一目录中,则可以使用相对或绝对路径。
答案 1 :(得分:1)
您应该注意您的工作空间,并且CSV文件位于同一目录中。
答案 2 :(得分:0)
我认为您应该将file.csv和.py放在同一文件夹中。