首页 > 解决方案 > 如何在 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

标签: pythonpandasyahoo-finance

解决方案


推荐阅读