0

I have a list filepath with the ubication of the files I need to read (115 files), I need to read those files and add columns header (same for all files), also I have a list with the files names I want to use but no idea in how make it.

filepath look like this

['drive/My Drive/forex/DAT_MT_BCOUSD_M1_2015.csv',
 'drive/My Drive/forex/DAT_MT_BCOUSD_M1_2016.csv',
 'drive/My Drive/forex/DAT_MT_BCOUSD_M1_2017.csv',
 'drive/My Drive/forex/DAT_MT_BCOUSD_M1_2018.csv',
 'drive/My Drive/forex/DAT_MT_BCOUSD_M1_2019.csv']

filename is like this

['DAT_MT_BCOUSD_M1_2015',
 'DAT_MT_BCOUSD_M1_2016',
 'DAT_MT_BCOUSD_M1_2017',
 'DAT_MT_BCOUSD_M1_2018',
 'DAT_MT_BCOUSD_M1_2019']

and I was adding the columns header like this

DAT_MT_BCOUSD_M1_2015= pd.read_csv("drive/My Drive/forex/DAT_MT_BCOUSD_M1_2015.csv",
                                    names=["Date","Time","Bar OPEN Bid Quote","Bar HIGH Bid Quote","Bar 
                                    LOW Bid Quote","Bar CLOSE Bid Quote","Volume"])

any ideas on how aproach the problem?

1

1 Answer 1

1

I'd suggest you create a Python dictionary with the dataframes inside, and access them using their filenames as the dictionary keys.

new_dict = {filename: pd.read_csv("drive/My Drive/forex/{}.csv".format(filename),
                                  names=["Date","Time","Bar OPEN Bid Quote",
                                         "Bar HIGH Bid Quote","Bar LOW Bid Quote",
                                         "Bar CLOSE Bid Quote","Volume"]) \
            for filename in filename_list}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.