“CSV file does not exist” for a filename with embedded quotes

前端 未结 18 704
萌比男神i
萌比男神i 2020-12-15 23:16

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:

imp         


        
相关标签:
18条回答
  • 2020-12-15 23:58

    Try this

    import os 
    cd = os.getcwd()
    dataset_train = pd.read_csv(cd+"/Google_Stock_Price_Train.csv")
    
    0 讨论(0)
  • 2020-12-15 23:59

    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

    0 讨论(0)
  • 2020-12-16 00:00

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

    0 讨论(0)
  • 2020-12-16 00:00

    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 :-)

    0 讨论(0)
  • 2020-12-16 00:00

    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



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

    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:
    

    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

    0 讨论(0)
  • 2020-12-16 00:00

    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.

    0 讨论(0)
提交回复
热议问题