Search code examples
pythonpandascsvmachine-learningspyder

CSV file not found even though it exists (FileNotFound [Errno 2])


I was trying to read a dataset but I'm getting this weird error:

FileNotFoundError: [Errno 2] File b'Position_Salaries.csv' does not exist: b'Position_Salaries.csv'

Even though the file does exist and its on the same directory of my code (As you can see in this pic)

The weird thing is, I've run that code many times without getting any kind of error, but suddenly (without changing anything)is not working. I literally just opened Spyder, try to run the code, but nope, that error appeared. Any ideas why is this happening and how can I solve it?

Part of the code I'm trying to run:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

dataset = pd.read_csv('Position_Salaries.csv')
X = dataset.iloc[:, 1:2].values 
y = dataset.iloc[:, 2].values

Solution

  • There is a tool tip that is obscuring your picture but from the information provided I would guess that your working directory is not set to your project directory. Try running the code from the terminal.