pandas.Series.diff
pandas.Series.pct_change
nikkei225['Close']
nikkei225['Close'].diff()
periods
の値を指定することで可能です。nikkei225['Close'].diff(2)
nikkei225['Close'].pct_change()
nikkei225['Close'].pct_change(2)
nikkei225['diff'] = nikkei225['Close'].diff()
nikkei225['pct_change'] = nikkei225['Close'].pct_change()
nikkei225[['Close', 'diff', 'pct_change']]
Close | diff | pct_change | |
---|---|---|---|
Date | |||
2022-05-26 | 26604.839844 | NaN | NaN |
2022-05-27 | 26781.679688 | 176.839844 | 0.006647 |
2022-05-30 | 27369.429688 | 587.750000 | 0.021946 |
2022-05-31 | 27279.800781 | -89.628906 | -0.003275 |
2022-06-01 | 27457.890625 | 178.089844 | 0.006528 |
diff
, pct_change
の例でした。