Reputation: 1
I am going through w3school's machine learning course and I am stuck on the Multiple Regression section. I downloaded their example CSV file and when I ran the following code:
import pandas
from sklearn import linear_model
df = pandas.read_csv("data.csv")
X = df[['Weight', 'Volume']]
y = df['CO2']
regr = linear_model.LinearRegression()
regr.fit(X, y)
predictedCO2 = regr.predict([[2300, 1300]])
print(predictedCO2)
I got this error:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-34-a25fe74bc066> in <cell line: 4>()
2 from sklearn import linear_model
3
----> 4 df = pandas.read_csv("data.csv")
5
6 X = df[['Weight', 'Volume']]
4 frames
/usr/local/lib/python3.10/dist-packages/pandas/io/common.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
857 if ioargs.encoding and "b" not in ioargs.mode:
858 # Encoding
--> 859 handle = open(
860 handle,
861 ioargs.mode,
FileNotFoundError: [Errno 2] No such file or directory: 'data.csv'
So before looking anything up I checked the file to see if it was there and when I found it there I assumed that I should just make a copy, change the name, and use the new name for the file.
df = pandas.read_csv("co2.csv")
This did absolutely nothing to fix the problem. So, I looked into it and found that I needed the full path directory for file and copied the path that Mac has in the 'Where:' of the info page:
df = pandas.read_csv("/Users/drewolson/Documents/co2.csv")
Still nothing and I am utterly confused because everything I looked up said it would be solved by having the entire path directory and I swear I do. What am I missing?
Upvotes: 0
Views: 116