0

I have a csv file which is located on my computer, the path looks like: Macintosh HD/somefolder/anotherfolder/onemorefolder/file.csv

However when I try to import that csv as a dataframe in pandas using the code:

df = pd.read_csv("/Macintosh HD/somefolder/anotherfolder/onemorefolder/file.csv", sep =";")

PyCharm returns an error claiming there is no such directory or file. OKay, I insert a direct link where the same csv is located online, in this case the code looks like:

df = pd.read_csv("https://disk.yandex.ru/d/yaPJSq26gFvxHw", sep =";")

and now PyCharm says:

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)>

What's wrong in my code and why don't I manage to import that csv directly from my mac?

ela rednax
  • 53
  • 1
  • 8
  • Check [this](https://apple.stackexchange.com/a/338899) answer to get the correct `path` to your `csv` file. – RJ Adriaansen Mar 27 '21 at 13:53
  • What does `os.path.exists("/Macintosh HD/somefolder/anotherfolder/onemorefolder/file.csv")` return? –  Mar 27 '21 at 13:56
  • This question could you help you out for the second problem: https://stackoverflow.com/questions/50236117/scraping-ssl-certificate-verify-failed-error-for-http-en-wikipedia-org – George Adams Mar 27 '21 at 13:59

2 Answers2

0

You can use relative path by putting the csv in the same folder with the script or notebook you are trying to read the csv.

df = pd.read_csv('file.csv', sep=';')

or in a folder that is in the same folder with the script/notebook:

df = pd.read_csv('name_of_the_folder/file.csv', sep=';')

The link you are using is not the url of the csv file, it is the url of the web page you can download the csv so it won't work.

Metehan Kutlu
  • 178
  • 10
0

I think this is a path problem rather than a pandas issue. Try opening the same file with the built-in open() function. To get the correct path to navigate over to the directory containing the csv file and write pwd in the terminal (for macOS). Copy this path and just append the <filename>.csv

Possible Solutions


  1. Move the file.csv to the same folder as the python script or Jupyter Notebook and then simply use pd.read_csv("file.csv", sep = ";").

  2. The URL which you shared redirects to a page but doesn't download the csv file directly. If you have the file available in s3 or gs, try using that link.

Saurav Maheshkar
  • 183
  • 1
  • 11