Read CSV from desktop of MacBook Pro into Pandas dataframe

17,069

This is a tricky problem to help with, since I think we need more information about the file and perhaps post your error code and what you expect the file to be called. A very basic step that has caused me to me stumble many times is to be sure that there aren't any typos in the file path. You could also try moving the file to the same folder that your notebook is in and then just read the file in using pd.read_csv("LynnCrimeRatePerCapita.csv"). Finally, you could try opening a terminal, cd-ing directories until you're in the folder with the file you want, then type pwd to print the path to the file, highlight that path using your mouse, ctrl+click (since you're on a Mac), copy the path, then paste it into your code.

Share:
17,069
Larry Field
Author by

Larry Field

Updated on June 04, 2022

Comments

  • Larry Field
    Larry Field almost 2 years
    crpcdf=pd.read_csv("/Users/gina/Desktop/LynnCrimeRatePerCapita.csv")
    crpcdf.head()
    

    The above are a sample of the approaches I've tried. I always get the nonexistent file or path message. Doing this from Jupyter notebook. While trying other tricks, it would also not let me change my working directory to my desktop. Nonexistent again. What do I do? Thanks.

    Yes, I'm in Jupyter Notebook.

    • m13op22
      m13op22 about 5 years
      Maybe providing a better explanation would help us help you.
  • Larry Field
    Larry Field about 5 years
    When I open Terminal, I see that the Mac equivalent of the "C" drive is "Virginias-MBP". I thought it was the first directory I saw in Finder, "MBP_HD", so I changed my read to include the MBP_HD. Same result. Here is the message: FileNotFoundError: File b'C:/MBP_HD/Users/gina/Desktop/LynnCrimeRatePerCapita.cvs' does not exist the "b'C:" throws me. Is this a clue? Also, when I do print(os.getcwd()), I get: /home/dsxuser/work
  • Larry Field
    Larry Field about 5 years
    Also, when I do print(os.getcwd()), I get: /home/dsxuser/work I don't see "home" in finder. So, I don't know how to find a working directory so that I can just stick the file there. A little out of my league here.
  • Larry Field
    Larry Field about 5 years
    More piddling with Terminal. I can't go any further upstream than Virginias-MBP: gina$. Note the space after the :. Is that part of command syntax or part of directory name? Also, when I cd all the way to desktop, I find the file. When I pwd, it gives me /Users/gina/Desktop. The original " gina" is not included. But, an ls when in ": gina" shows Users as an included directory. Now, when I chimp it, all possible combinations of directory lists I can make of this information produce the same error message as above.
  • m13op22
    m13op22 about 5 years
    @LarryField if your file is on your Desktop, then the path /Users/gina/Desktop/LynnCrimeRatePerCapita.csv should be enough. If you type !pwd in your Jupyter notebook, what do you get?
  • Larry Field
    Larry Field about 5 years
    I get: /home/dsxuser. If I do a ls, I get: jars/ notebook/ work/. This is all part of a directory pathworks that is not visible in Finder. How can I transfer files into a working directory that is not visible? Also, chdir() attempts result in 'path doesn't exist' fault. It's as if the Notebook has created a partition in the Mac drive and the other side of the partition is totally invisible to it.
  • Larry Field
    Larry Field about 5 years
    If I try to cp the file from the desktop to the /home directory in Terminal, I get this message:cp: /home/ACS_17_5YR_S0601_with_ann.csv: Operation not supported
  • Larry Field
    Larry Field about 5 years
    home and Users are both visible when I do an ls in Terminal when the prompt is at the root drive.
  • m13op22
    m13op22 about 5 years
    I would think you'd need to copy it to /Users/gina/Desktop, not the /home directory. Copying to the /home directory is more for Linux, I think. You may have better luck posting on the Apple Stack Exchange, or hopefully someone else with more knowledge than me can help. Maybe post more of your script?
  • Larry Field
    Larry Field about 5 years
    It is on /Users/gina/Desktop. I was trying to copy to /home. I've given up and decided to copy file to my Github space then read it from there. Naturally, I'm on to a new problem. I get the following error. Am I supposed to do something special re Github? Or what? XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\n\n\n\n\n\n<!'
  • m13op22
    m13op22 about 5 years
    For that, consider asking a new question with your error and some sample code. I don't think I'm the best person to help you there. Sorry.
  • Larry Field
    Larry Field about 5 years
    Thanks for your help. Eventually this little adventure will come to a satisfying end. I'll remember to close this thread with the final explanation... I hope.
  • Larry Field
    Larry Field about 5 years
    I just got it. Or one of the solutions. To get file download URL, do not Ctrl-Click on file name; go to 'View Raw' page and Ctrl-Click on the 'Download' button. Slightly different, and correct, URL.
  • m13op22
    m13op22 about 5 years
    That's fantastic!