Kyle
Kyle

Reputation: 11

FileNotFoundError: [Errno 2] No such file or directory: './iris.csv'

So I'm getting a new error with my Python IDLE code, I'm not sure what to do. Any help would be greatly appreciated!

Traceback (most recent call last):
  File "C:\Users\kyle_\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\core\indexes\base.py", line 3800, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 165, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 5745, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 5753, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'iris'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\kyle_\OneDrive\Documents\COIS 4400H\Lab 5.py", line 23, in <module>
    iris_df['iris'].drop_duplicates()
  File "C:\Users\kyle_\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\core\frame.py", line 3805, in __getitem__
    indexer = self.columns.get_loc(key)
  File "C:\Users\kyle_\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\core\indexes\base.py", line 3802, in get_loc
    raise KeyError(key) from err
KeyError: 'iris'

Upvotes: 1

Views: 138

Answers (1)

pyrifo
pyrifo

Reputation: 107

Looks like you are looking in the file path that ends with \Lab 5 .py, which will just contain your python script. So you need to look one layer "above" your python script, which is the directory containing the script and the iris.csv-file.

Try: iris_df = pd.read_csv('../iris.csv')

Upvotes: 1

Related Questions