Reputation: 37
I want to create multiple empty pd.DataFrame and I thought I can do it with a loop like this:
for share in tickers:
share=pd.DataFrame()
with:
tickers=['AAPL', 'MSFT', '^GSPC', 'VNA.DE', '^GDAXI', 'HJUE.HA', 'GYC.DE', '2B7K.DE']
But this creates a empty DataFrame named "share" and not 8 different Dataframe named like AAPL, MSFT,...
Upvotes: 0
Views: 230
Reputation: 863226
It is not recommended, better is create dictionary of DataFrame
s:
dfs = {x: pd.DataFrame() for x in tickers}
print (dfs)
{'AAPL': Empty DataFrame
Columns: []
Index: [], 'MSFT': Empty DataFrame
Columns: []
Index: [], '^GSPC': Empty DataFrame
Columns: []
Index: [], 'VNA.DE': Empty DataFrame
Columns: []
Index: [], '^GDAXI': Empty DataFrame
Columns: []
Index: [], 'HJUE.HA': Empty DataFrame
Columns: []
Index: [], 'GYC.DE': Empty DataFrame
Columns: []
Index: [], '2B7K.DE': Empty DataFrame
Columns: []
Index: []}
And then select by keys:
print (dfs['AAPL'])
Empty DataFrame
Columns: []
Index: []
Upvotes: 1