Last answered:

16 Mar 2021

Posted on:

04 Oct 2019

0

Resolved: Importing an Excel document onto Python

Using Jupyter on a Mac, I cannot import my .csv Excel file onto Python.  I get this error: FileNotFoundError: [Errno 2] File b'real_estate_price_size.csv' does not exist: b'real_estate_price_size.csv' I got a response from 365 Data Science saying the files must all be in the same directory, though I am not sure which files 365 Data Science is referring to.  Any ideas?  
3 answers ( 0 marked as helpful)
Instructor
Posted on:

07 Oct 2019

1
This is an issue that occurs due to your specific Anaconda installation. The easiest way to solve this is to reinstall Anaconda. However, we recommend that you use the absolute path of a file when loading the data.   Thus, you can write:
data = pd.read_csv(‘ABSOLUTE_PATH/real_esate_price_size.csv’)
To me this looks like:
data = pd.read_csv('C:/Users/365/Desktop/The Data Science Course 2018 – All Resources/Part_4_Advanced_Statistical_Methods_(Machine_Learning)/S27_L142/real_estate_price _size.csv') 
In your case, you can find that by opening the folder containing the files and copy-pasting the path. Once you copy-paste this path, you should CHANGE ALL SLASHES from backward to forward. This means that if your path is C:\Users\YOUR_COMPUTER_NAME\Desktop\... , you should make it look like: C:/Users/YOUR_COMPUTER_NAME/Desktop/… Note that, due to the standards for referencing paths, in Python, instead of a backward slash ( \ ), you should use a forward slash ( / ).
Posted on:

16 Mar 2021

0

When you open a file with the file name , you are telling the open() function that your file is in the current working directory. This is called a relative path. If the user does not pass the full path to the file (on Unix type systems this means a path that starts with a slash), the path is interpreted relatively to the current working directory. The current working directory usually is the directory in which you started the program. A good start would be validating the input. In other words, you can make sure that the user has indeed typed a correct path for a real existing file, like this:

while not os.path.isfile(fileName):
    fileName = input("No such file! Please enter the name of the file you'd like to use.")

Another way to tell the python file open() function where your file is located is by using an absolute path, e.g.:

f = open("/Users/foo/filename")

Submit an answer