Computes the difference between consecutive values in the Index object. If periods is greater than 1, computes the difference between values that are `periods` number of positions apart. Parameters ---------- periods : int, optional The
(self, periods: int = 1)
| 7320 | |
| 7321 | @final |
| 7322 | def diff(self, periods: int = 1) -> Index: |
| 7323 | """ |
| 7324 | Computes the difference between consecutive values in the Index object. |
| 7325 | |
| 7326 | If periods is greater than 1, computes the difference between values that |
| 7327 | are `periods` number of positions apart. |
| 7328 | |
| 7329 | Parameters |
| 7330 | ---------- |
| 7331 | periods : int, optional |
| 7332 | The number of positions between the current and previous |
| 7333 | value to compute the difference with. Default is 1. |
| 7334 | |
| 7335 | Returns |
| 7336 | ------- |
| 7337 | Index |
| 7338 | A new Index object with the computed differences. |
| 7339 | |
| 7340 | Examples |
| 7341 | -------- |
| 7342 | >>> import pandas as pd |
| 7343 | >>> idx = pd.Index([10, 20, 30, 40, 50]) |
| 7344 | >>> idx.diff() |
| 7345 | Index([nan, 10.0, 10.0, 10.0, 10.0], dtype='float64') |
| 7346 | |
| 7347 | """ |
| 7348 | return Index(self.to_series().diff(periods)) |
| 7349 | |
| 7350 | def round(self, decimals: int = 0) -> Self: |
| 7351 | """ |