bigframes.pandas.DataFrame.diff#
- DataFrame.diff(periods: int = 1) DataFrame[source]#
First discrete difference of element.
Calculates the difference of a DataFrame element compared with another element in the DataFrame (default is element in previous row).
Examples:
>>> df = bpd.DataFrame({"A": [3, 1, 2], "B": [1, 2, 3]}) >>> df A B 0 3 1 1 1 2 2 2 3 [3 rows x 2 columns]
Calculating difference with default periods=1:
>>> df.diff() A B 0 <NA> <NA> 1 -2 1 2 1 1 [3 rows x 2 columns]
Calculating difference with periods=-1:
>>> df.diff(periods=-1) A B 0 2 -1 1 -1 -1 2 <NA> <NA> [3 rows x 2 columns]
- Parameters:
periods (int, default 1) – Periods to shift for calculating difference, accepts negative values.
- Returns:
First differences of the Series.
- Return type: