periods: Express shift Range of movement , A positive number means to move down , Negative numbers move up , The default value is 1, After the move, there is no value, and the index is missing
freq: according to freq The parameter value is used as the interval moving time index , The data value does not change , About freq You can obtain values for reference date_range Create date range freq Parameter value table and creation example _ I am a little monster blog -CSDN Blog
>>> import pandas as pd
>>> date_index=pd.date_range('2022-01-01',periods=6)
>>> time=pd.Series(range(6),index=date_index)
>>> print(time)
2022-01-01 0
2022-01-02 1
2022-01-03 2
2022-01-04 3
2022-01-05 4
2022-01-06 5
Freq: D, dtype: int64
>>> time.shift(periods=2)# Move down the 2 Time
2022-01-01 NaN
2022-01-02 NaN
2022-01-03 0.0
2022-01-04 1.0
2022-01-05 2.0
2022-01-06 3.0
Freq: D, dtype: float64
>>> time.shift(periods=-2)# Move up 2 Time
2022-01-01 2.0
2022-01-02 3.0
2022-01-03 4.0
2022-01-04 5.0
2022-01-05 NaN
2022-01-06 NaN
Freq: D, dtype: float64
>>> time.shift(periods=-2,freq='2D')# Every two days , Move up twice , So the time index shifted for four days
2021-12-28 0
2021-12-29 1
2021-12-30 2
2021-12-31 3
2022-01-01 4
2022-01-02 5
Freq: D, dtype: int64
>>> time.shift(periods=-1,freq='2D')
2021-12-30 0
2021-12-31 1
2022-01-01 2
2022-01-02 3
2022-01-03 4
2022-01-04 5
Freq: D, dtype: int64