modin.pandas.SeriesGroupBy.shift¶
- SeriesGroupBy.shift(periods: int = 1, freq: int = None, axis: Union[int, Literal['index', 'columns', 'rows']] = 0, fill_value: Any = None)[source]¶
- Shift each group by periods observations. - If freq is passed, the index will be increased using the periods and the freq. - Parameters:
- periods (int, default 1) – Number of periods to shift. 
- freq (str, optional) – Frequency string. 
- axis (axis to shift, default 0) – Shift direction. Snowpark pandas does not yet support axis=1. 
- fill_value (optional) – The scalar value to use for newly introduced missing values. 
 
- Returns:
- Object shifted within each group. 
- Return type:
 - Examples - For SeriesGroupBy: - >>> lst = ['a', 'a', 'b', 'b'] >>> ser = pd.Series([1, 2, 3, 4], index=lst) - >>> ser a 1 a 2 b 3 b 4 dtype: int64 - >>> ser.groupby(level=0).shift(1) a NaN a 1.0 b NaN b 3.0 dtype: float64 - For DataFrameGroupBy: - >>> data = [[1, 2, 3], [1, 5, 6], [2, 5, 8], [2, 6, 9]] >>> df = pd.DataFrame(data, columns=["a", "b", "c"], ... index=["tuna", "salmon", "catfish", "goldfish"]) - >>> df a b c tuna 1 2 3 salmon 1 5 6 catfish 2 5 8 goldfish 2 6 9 - >>> df.groupby("a").shift(1) b c tuna NaN NaN salmon 2.0 3.0 catfish NaN NaN goldfish 5.0 8.0