安装python
传入股票编码,开始结束日期,可以获取该股票历史的所有数据,并写入到excel中
## 可以在该网站上搜索具体号码:https://hk.finance.yahoo.com/quote/000829.SZ/,在右边输入股票信息 ,比如新华传媒为:600825.SS
如果觉得有帮助请给个免费的评分,谢谢
[Python] 纯文本查看 复制代码 import yfinance as yf
import pandas as pd
ticker = input('请输入股票号码:') ## 可以在该网站上搜索具体号码:https://hk.finance.yahoo.com/quote/000829.SZ/,在右边输入股票信息 ,比如新华传媒为:600825.SS
start_date = input('请输入开始日期:')
end_date = input('请输入结束日期:')
# # 定义股票代码和时间范围
# ticker = "000829.SZ"
# start_date = "2023-01-01"
# end_date = "2024-06-01"
# 下载股票数据
data = yf.download(ticker, start=start_date, end=end_date)
# 显示前几行数据
# print(data.tail())
excel_name = ticker[0:6]
# print(excel_name)
data.to_excel(f'{excel_name}.xlsx',index_label=False) |