【发布时间】:2021-12-22 08:50:01
【问题描述】:
我想请教一下如何迭代链接并保存数据。
我正在使用 Alpha Vantage,他们只允许每个请求在 1 个月内进行日内分钟交易。为了获得第二个月,您必须更改链接中的 slice 参数。
我想创建一个 for 循环,该循环遍历我的列表并提取每个月的数据并将其保存在数据框中。以下是获取数据的步骤以及我到目前为止所做的事情。
这只给了我 year2month2 而不是整个时期。有人可以在这里指导我我做错了什么
# replace the "demo" apikey below with your own key from https://www.alphavantage.co/support/#api-key
symbol = 'pltr'
interval = '1min'
periods=['year1month1','year1month2','year1month3','year1month4','year1month5',
'year1month6','year1month7','year1month8','year1month9','year1month10',
'year1month11','year1month12','year2month1','year2month2','year2month3',
'year2month4','year2month5','year2month6','year2month7','year2month8',
'year2month9','year2month10','year2month11','year2month12']
df=[]
for period in periods:
df = pd.read_csv('https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY_EXTENDED&symbol='+ticker+'&interval=15min&slice='+period+'&apikey='+apiKey+'&datatype=csv&outputsize=full')
df.append(period)
#Show output
print(df)
【问题讨论】:
-
我会使用
pandas.read_csv而不是csv.reader -
感谢您的回复,但没有成功
标签: python pandas for-loop alpha-vantage