我正在尝试从yfinance下载股票数据。我有一个名为ticker_list_1的股票报价器列表,其中包含一堆符号。其结构如下:
array(['A', 'AAP', 'AAPL', 'ABB', 'ABBV', 'ABC', 'ABEV', 'ABMD', 'ABNB',....
现在我使用下面的代码来下载数据:
i = 0
xrz_data = {}
for i, len in enumerate (ticker_list_1):
data = yf.download(ticker_list_1[i], start ="2019-01-01", end="2022-10-20")
xrz_data[i] = data
i=i+1
我遇到的问题是,一旦下载了数据,数据就保存为xrz_data。我可以通过代码xrz_data[I]
和相应的编号访问特定的数据集。但是,我希望能够通过xrz_data[tickername]访问数据。
我如何才能做到这一点?
我试过使用xrz_data[i].values = data
,它给了我错误KeyError:0
下面是for循环的当前输出:
{0: Open High Low Close Adj Close \
Date
2018-12-31 66.339996 67.480003 66.339996 67.459999 65.660202
2019-01-02 66.500000 66.570000 65.300003 65.690002 63.937435
2019-01-03 65.529999 65.779999 62.000000 63.270000 61.582008
2019-01-04 64.089996 65.949997 64.089996 65.459999 63.713589
2019-01-07 65.639999 67.430000 65.610001 66.849998 65.066483
... ... ... ... ... ...
2022-10-13 123.000000 128.830002 122.349998 127.900002 127.900002
2022-10-14 129.000000 130.220001 125.470001 125.699997 125.699997
2022-10-17 127.379997 131.089996 127.379997 130.559998 130.559998
2022-10-18 133.919998 134.679993 131.199997 132.300003 132.300003
2022-10-19 130.110001 130.270004 127.239998 128.960007 128.960007
[959 rows x 6 columns],
1: Open High Low Close Adj Close \
Date
2018-12-31 156.050003 157.679993 154.990005 157.460007 149.844055
2019-01-02 156.160004 159.919998 153.820007 157.919998 150.281815
........
我期望的输出是:
AAP: Open High Low Close Adj Close \
Date
2018-12-31 156.050003 157.679993 154.990005 157.460007 149.844055
2019-01-02 156.160004 159.919998 153.820007 157.919998 150.281815
........
1条答案
按热度按时间j8ag8udp1#
我能够弄清楚它。通过下面的代码,我能够下载数据,并通过f.e.
xrz_data['AAPL‘]
访问特定的股票报价器