[python] "CSV file does not exist" for a filename with embedded quotes

I am currently learning Pandas for data analysis and having some issues reading a csv file in Atom editor.

When I am running the following code:

import pandas as pd 

df = pd.read_csv("FBI-CRIME11.csv")

print(df.head())

I get an error message, which ends with

OSError: File b'FBI-CRIME11.csv' does not exist

Here is the directory to the file: /Users/alekseinabatov/Documents/Python/"FBI-CRIME11.csv".

When i try to run it this way:

df = pd.read_csv(Users/alekseinabatov/Documents/Python/"FBI-CRIME11.csv")

I get another error:

NameError: name 'Users' is not defined

I have also put this directory into the "Project Home" field in the editor settings, though I am not quite sure if it makes any difference.

I bet there is an easy way to get it to work. I would really appreciate your help!

This question is related to python csv pandas atom-editor

The answer is


Adnane's answer helped me.

Here's my full code on mac, hope this helps someone. All my csv files are saved in /Users/lionelyu/Documents/Python/Python Projects/

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('ggplot')

path = '/Users/lionelyu/Documents/Python/Python Projects/'

aapl = pd.read_csv(path + 'AAPL_CLOSE.csv',index_col='Date',parse_dates=True)
cisco = pd.read_csv(path + 'CISCO_CLOSE.csv',index_col='Date',parse_dates=True)
ibm = pd.read_csv(path + 'IBM_CLOSE.csv',index_col='Date',parse_dates=True)
amzn = pd.read_csv(path + 'AMZN_CLOSE.csv',index_col='Date',parse_dates=True)

In my case I just removed .csv from the end. I am using ubuntu.

pd.read_csv("/home/mypc/Documents/pcap/s2csv")

Just change the CSV file name. Once I changed it for me, it worked fine. Previously I gave data.csv then I changed it to CNC_1.csv.


What worked for me:

import csv
import pandas as pd
import os

base =os.path.normpath(r"path")



with open(base, 'r') as csvfile:
    readCSV = csv.reader(csvfile, delimiter='|')
    data=[]
    for row in readCSV:
        data.append(row)
    df = pd.DataFrame(data[1:],columns=data[0][0:15])
    print(df)


This reads in the file , delimit by |, and appends to list which is converted to a pandas df (taking 15 columns)

I had the same issue, but it was happening because my file was called "geo_data.csv.csv" - new laptop wasn't showing file extensions, so the name issue was invisible in Windows Explorer. Very silly, I know, but if this solution doesn't work for you, try that :-)


I am using a Mac. I had the same problem wherein .csv file was in the same folder where the python script was placed, however, Spyder still was unable to locate the file. I changed the file name from capital letters to all small letters and it worked.


Run "pwd" command first in cli to find out what is your current project's direction and then add the name of the file to your path!


I also experienced the same problem I solved as follows:

dataset = pd.read_csv('C:\\Users\\path\\to\\file.csv')

Being on jupyter notebook it works for me including the relative path only. For example:

df = pd.read_csv ('file.csv')

But, for example, in vscode I have to put the complete path:

df = pd.read_csv ('/home/code/file.csv')

What works for me is

dataset = pd.read_csv('FBI_CRIME11.csv')

Highlight it and press enter. It also depends on the IDE you are using. I am using Anaconda Spyder or Jupiter.


Try this

import os 
cd = os.getcwd()
dataset_train = pd.read_csv(cd+"/Google_Stock_Price_Train.csv")

Sometimes we ignore a little bit issue which is not a Python or IDE fault its logical error We assumed a file .csv which is not a .csv file its a Excell Worksheet file have a look


Tiktok file which is worksheet file not a CSV file Shown in Green border


When you try to open that file using Import compiler will through the error have a look enter image description here

To Resolve the issue

open your Target file into Microsoft Excell and save that file in .csv format it is important to note that Encoding is important because it will help you to open the file when you try to open it with

with open('YourTargetFile.csv','r',encoding='UTF-8') as file:

enter image description here

So you are set to go now Try to open your file as this

import csv
with open('plain.csv','r',encoding='UTF-8') as file:
load = csv.reader(file)
for line in load:
    print(line)

Here is the Output Plain.csv File Running


Had an issue with the path, it turns out that you need to specify the first '/' to get it to work! I am using VSCode/Python on macOS


You are missing '/' before Users. I assume that you are using a MAC guessing from the file path names. You root directory is '/'.


Make sure your source file is saved in .csv format. I tried all the steps of adding the full path to the file, including and deleting the header=0, adding skiprows=0 but nothing works as I saved the excel file(data file) in workbook format and not in CSV format. so keep in mind to first check your file extension.


If you get this type of Error

Then fix the path of the directory


Just referring to the filename like

df = pd.read_csv("FBI-CRIME11.csv")

generally only works if the file is in the same directory as the script.

If you are using windows, make sure you specify the path to the file as follows:

PATH = "C:\\Users\\path\\to\\file.csv"

Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to csv

Pandas: ValueError: cannot convert float NaN to integer Export result set on Dbeaver to CSV Convert txt to csv python script How to import an Excel file into SQL Server? "CSV file does not exist" for a filename with embedded quotes Save Dataframe to csv directly to s3 Python Data-frame Object has no Attribute (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape How to write to a CSV line by line? How to check encoding of a CSV file

Examples related to pandas

xlrd.biffh.XLRDError: Excel xlsx file; not supported Pandas Merging 101 How to increase image size of pandas.DataFrame.plot in jupyter notebook? Trying to merge 2 dataframes but get ValueError Python Pandas User Warning: Sorting because non-concatenation axis is not aligned How to show all of columns name on pandas dataframe? Pandas/Python: Set value of one column based on value in another column Python Pandas - Find difference between two data frames Pandas get the most frequent values of a column Python convert object to float

Examples related to atom-editor

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How to open the terminal in Atom? "CSV file does not exist" for a filename with embedded quotes Commenting out code blocks in Atom How can I jump to class/method definition in Atom text editor? How to run a program in Atom Editor? Atom menu is missing. How do I re-enable Running Python from Atom Is there a command for formatting HTML in the Atom editor? How to auto-indent code in the Atom editor?