首页 > 解决方案 > Pandas read_csv 中的错误

问题描述

这是我的代码:

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 但它仍然无法正常工作有人可以帮助我吗?

标签: pythonpandascsvdebuggingmachine-learning

解决方案


您应该知道您的工作区和 CSV 文件位于同一目录中。


推荐阅读