python - 如何在 pandas DataFrame 中生成第二天的价格?
问题描述
这是我的片段:
import yfinance as yf
msft = yf.Ticker("MSFT")
hist = msft.history(period="1y")
print(hist)
DataFrame 如下所示:
Open High Low Close Volume Dividends Stock Splits
Date
2020-03-20 144.53 145.62 134.49 135.97 84866200 0.0 0
2020-03-23 135.63 139.16 131.19 134.61 78975200 0.0 0
2020-03-24 142.30 148.10 139.85 146.85 82516700 0.0 0
2020-03-25 147.41 152.78 142.99 145.44 75638200 0.0 0
2020-03-26 146.91 155.08 146.88 154.54 64568100 0.0 0
我只想加一栏,就是下个交易日的收盘价。
我的期望是:
Open High Low Close Volume Dividends Stock Splits Next Close
Date
2020-03-20 144.53 145.62 134.49 135.97 84866200 0.0 0 134.61
2020-03-23 135.63 139.16 131.19 134.61 78975200 0.0 0 146.85
2020-03-24 142.30 148.10 139.85 146.85 82516700 0.0 0 145.44
2020-03-25 147.41 152.78 142.99 145.44 75638200 0.0 0 154.54
2020-03-26 146.91 155.08 146.88 154.54 64568100 0.0 0
解决方案
推荐阅读
- android - 使用 js 中的 navigator.mediaDevices.getUserMedia 在 webview 中访问相机
- sql - REF 表的范围
- email - 替换 Outlook 电子邮件中的百分比
- java - 搜索最小 k 值的 PriorityQueue 算法返回不正确的结果
- kubernetes - Kubernetes 上的 ActiveMQ 代理 URL
- centos - 是否有可能更改 podman 容器的重启策略?
- javascript - 如何向幻灯片添加说明?
- java - 使用 Java Swing 将 JTable 中的内容输出到 TextArea
- ruby-on-rails - 多对多关系
- python - ValueError:使用 PIL 加载图像时设置带有序列的数组元素