0

I have been struggling to create separated Dataframes for each csv inside the directory + folder. Wondering how would be the best approuch ..

First part.I go over directories to list all csv files, appending in first list called (test) the files csv....and second list called (testList), the names abreviation to be used as name of the Dataframes.

    import os
    
    test = [] 
    testList = []

    for i in os.listdir('Hist/'):
        for ii in os.listdir(i):
            test.append(ii)
            path_list = ii.split(os.sep)
            name = path_list[0:4][-1][:9]
            testList.append(name) 

After, I'm trying to get df created using both list. test reading as csv and testList to be used as name of the DF. However, getting error:

     data = {}
     for k, v in zip(testList,test):
     data[k] = (read_csv(v,sep='\s+',index_col='<DATE>',parse_dates=True)) 

FileNotFoundError:

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Dicast
  • 69
  • 7
  • Possible duplicate of [Import multiple csv files into pandas and concatenate into one DataFrame](https://stackoverflow.com/questions/20906474/import-multiple-csv-files-into-pandas-and-concatenate-into-one-dataframe) – sarthak Feb 21 '18 at 18:55
  • This has nothing to do with pandas. Jus try to change the test append to the following: `test.append(os.path.join(i,ii))` – Anton vBR Feb 21 '18 at 18:56
  • thanks for your asnwer.. using: test.append(os.path.join(i,ii)) will give the whole name. Dict and file.. 'AU\\AUDUSD_4 Hours_Bid_2012.01.31_2018.02.16.csv' However, trying to a df created with abreviation generated on testList ..., Exameple - DF 'AUDUSD_4 ', for file AUDUSD_4 Hours_Bid_2012.01.31_2018.02.16.csv' testList I have the names.. test ,, I have csv files. but, hen I tried to create the DF ..I got errors.. not sure, how to proceed. – Dicast Feb 21 '18 at 19:03
  • is there some way to perform like: test.append(os.path(ii).glob('/*.csv')) – Dicast Feb 21 '18 at 19:45

0 Answers0