Ai
1 Star 0 Fork 0

johnforrest/pythonoffice

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
35pandastushare.py 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
johnforrest 提交于 2022-03-27 11:16 +08:00 . 2022.03.27 自动化办公
# coding=utf-8
import tushare as ts
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
ts.set_token('bf45a7b0187fa900b6c90d09724a9de5b7668980c1e17a21aa34fdb5')
print(ts.__version__)
pro = ts.pro_api()
stock_info = pro.stock_basic() # 股票基本信息
# print(pro,stock_info)
# 中国电建集团 中南勘测设计研究院有限公司
dailyK = ts.get_hist_data('601669') # 一次性获取全部日k线数据
print(dailyK)
# todo :使用绝对路径,并且路径前必须加r,导出数据
dailyK.to_excel(r"F:\data\zny.xlsx") # 注意导出的文件后缀要写成.xlsx
# writer=pd.ExcelWriter(r"F:/zny.xlsx")
# dailyK.to_excel(writer,"sheet1")
# dailyK.to_excel("zny.xlsx")
#TODO: 切片是从数据列开始的,不是从Excel中的第一列【标题】
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html
# 当日交易值,并变形
X=dailyK.iloc[:,2].values.reshape(-1,1)
print(X=dailyK.iloc[:,2].values)
Y=dailyK.iloc[:,4].values.reshape(-1,1)
print(Y=dailyK.iloc[:,4].values)
lrmodel=LinearRegression()
lrmodel.fit(X,Y)
plt.scatter(X,Y)
ypredict=lrmodel.predict(X)
plt.plot(X,ypredict,color="r")
plt.show()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/johnforrest/pythonoffice.git
git@gitee.com:johnforrest/pythonoffice.git
johnforrest
pythonoffice
pythonoffice
master

搜索帮助