pandas.DataFrame.diff
pandas 3.1.1 · DataFrame · method
Subtract an earlier observation from the current one. Change periods to adjust the distance.
Call syntax
DataFrame.diff(periods=1, axis=0)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
periods |
Optional Positional or keyword Default 1 |
int Set a count of generated observations or the number of steps to shift or compare. |
axis |
Optional Positional or keyword Default 0 |
{0 or 'index', 1 or 'columns'} Choose which axis the operation acts on. The accepted axis labels depend on the receiver. |
Returns
DataFrame