如何做到这一点,以便提取所有可用数据,而不是专门为此脚本键入日期范围?
可用选项日期如下。我怎样才能编写代码,以便它提取所有这些日期,而不必将它们全部输入到单独的行中?
<代码>2022-03-11、2022-03-18、2022-03-25、2022-04-01、2022-04-08、2022-04-14、2022-04-22、2022-05-20 , 2022-06-17, 2022-07-15, 2022-10-21, 2023-01-20, 2024-01-19
import yfinance as yf
gme = yf.Ticker("gme")
opt = gme.option_chain('2022-03-11')
print(opt)
The available options dates are below. How can I write a code so that it pulls all those dates instead of having to type them all out in a separate row?
2022-03-11, 2022-03-18, 2022-03-25, 2022-04-01, 2022-04-08, 2022-04-14, 2022-04-22, 2022-05-20, 2022-06-17, 2022-07-15, 2022-10-21, 2023-01-20, 2024-01-19
import yfinance as yf
gme = yf.Ticker("gme")
opt = gme.option_chain('2022-03-11')
print(opt)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,由于这些日期没有规则的模式,您应该创建一个日期列表。
创建列表后,您可以按照您的方式启动代码:
但是现在,因为您希望打印出所有内容,并且我假设您需要将其保存到文件中以获得更好的视图(如我已经检查了输出,我个人更喜欢 csv for
yfinance
),您可以这样做:First of all, as these dates have no regular pattern, you should create a list of the dates.
After you have created the list, you can initiate your code as how you have done:
But right now, since you would want to have everything being printed out, and I assume you would need to save it to file for a better view (as I have checked the output and I personally prefer csv for
yfinance
), you can do this: