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

前端 未结 18 703
萌比男神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:47

    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.

    0 讨论(0)
  • 2020-12-15 23:47

    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)
    
    0 讨论(0)
  • 2020-12-15 23:52

    I also experienced the same problem I solved as follows:

    dataset = pd.read_csv('C:\\Users\\path\\to\\file.csv')
    
    0 讨论(0)
  • 2020-12-15 23:56

    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"
    
    0 讨论(0)
  • 2020-12-15 23:57

    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)
    
    0 讨论(0)
  • 2020-12-15 23:57

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

    pd.read_csv("/home/mypc/Documents/pcap/s2csv")
    
    0 讨论(0)
提交回复
热议问题