snowflake.snowpark.modin.plugin.extensions.groupby_overrides.DataFrameGroupBy.shift¶
- DataFrameGroupBy.shift(periods: Union[int, Sequence[int]] = 1, freq: int = None, axis: Union[int, Literal['index', 'columns', 'rows']] = 0, fill_value: Any = None, suffix: Optional[str] = None)[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.26.0/snowpark-python/src/snowflake/snowpark/modin/plugin/extensions/groupby_overrides.py#L858-L886)¶
Shift each group by periods observations.
If freq is passed, the index will be increased using the periods and the freq.
- Parameters:
periods (int | Sequence[int], default 1) –
Number of periods to shift. Can be positive or negative. If an iterable of ints, the data will be shifted once by each int. This is equivalent to shifting by one value at a time and concatenating all resulting frames. The resulting columns will have the shift suffixed to their column names. For multiple periods, axis must not be 1.
Snowpark pandas does not currently support sequences of int for periods.
freq (DateOffset, tseries.offsets, timedelta, or str, optional) –
Offset to use from the tseries module or time rule (e.g. ‘EOM’).
Snowpark pandas does not yet support this parameter.
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.
suffix (str, optional) –
If str is specified and periods is an iterable, this is added after the column name and before the shift value for each shifted column name.
Snowpark pandas does not yet support this parameter.
- 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