The following dataframe etf_list is given:
etf_list = pd.DataFrame({'ISIN': ['IE00B4X9L533', 'IE00B0M62Q58', 'LU0292097234', 'IE00BF4RFH31'],
'Name': ['HSBC MSCI WORLD UCITS ETF', 'iShares MSCI World UCITS ETF', 'FTSE 100 Income UCITS ETF 1D', 'iShares MSCI World Small Cap UCITS ETF'],
'Anbieter': ['HSBC', 'iShares', 'Xtrackers', 'iShares' ],
'Extension': ['xls', 'csv', 'xlsx', 'csv' ]})
In the folder /ETF I have the following files, which were generated today on June 11, 2021:
- IE00B4X9L533_20210611.xls
- IE00B0M62Q58_20210611.csv
- LU0292097234_20210611.xlsx
- IE00BF4RFH31_20210611.csv
As you can see, the files have the following structure:
etf_list['ISIN'] + '_' + timestr + '.' + etf_list['Extension']
whereas timestr = time.strftime("%Y%m%d")
The objective is to create in a for loop dataframes for the files, where Anbieter in etf_list equals 'iShares'. The created dataframes shall have the name of ISIN in the dataframe etf_list. In order to achieve this I defined an empty dictionary df ={}
df = {}
for i, row in etf_list.iterrows():
if row['Anbieter']=='iShares':
df[row['ISIN']] = 'ETF/'+ row['ISIN'] + '_' + timestr + '.csv'
df[row['ISIN']] = pd.read_csv(df[row['ISIN']], sep=',',skiprows=2, thousands='.', decimal=',')
else:
pass
The problem with this approach is, in order to reference to the created dataframes, I have to call them with for instance df['IE00B0M62Q58'] or df['IE00BF4RFH31'], but my objective is to use IE00B0M62Q58 instead df['IE00B0M62Q58'] and IE00BF4RFH31 instead of df['IE00BF4RFH31'].
What do I have to do in order reach my goal? How do I have to adjust my code?