bigframes.pandas.api.typing.DataFrameGroupBy.shift#
- DataFrameGroupBy.shift(periods=1) Series[source]#
Shift each group by periods observations.
Examples:
For SeriesGroupBy:
>>> lst = ['a', 'a', 'b', 'b'] >>> ser = bpd.Series([1, 2, 3, 4], index=lst) >>> ser.groupby(level=0).shift(1) a <NA> a 1 b <NA> b 3 dtype: Int64
For DataFrameGroupBy:
>>> data = [[1, 2, 3], [1, 5, 6], [2, 5, 8], [2, 6, 9]] >>> df = bpd.DataFrame(data, columns=["a", "b", "c"], ... index=["tuna", "salmon", "catfish", "goldfish"]) >>> df.groupby("a").shift(1) b c tuna <NA> <NA> salmon 2 3 catfish <NA> <NA> goldfish 5 8 [4 rows x 2 columns]
- Parameters:
periods (int, default 1) – Number of periods to shift.
- Returns:
Object shifted within each group.
- Return type: