Round each value in the Index to the given number of decimals. Parameters ---------- decimals : int, optional Number of decimal places to round to. If decimals is negative, it specifies the number of positions to the left of the decimal point
(self, decimals: int = 0)
| 7348 | return Index(self.to_series().diff(periods)) |
| 7349 | |
| 7350 | def round(self, decimals: int = 0) -> Self: |
| 7351 | """ |
| 7352 | Round each value in the Index to the given number of decimals. |
| 7353 | |
| 7354 | Parameters |
| 7355 | ---------- |
| 7356 | decimals : int, optional |
| 7357 | Number of decimal places to round to. If decimals is negative, |
| 7358 | it specifies the number of positions to the left of the decimal point. |
| 7359 | |
| 7360 | Returns |
| 7361 | ------- |
| 7362 | Index |
| 7363 | A new Index with the rounded values. |
| 7364 | |
| 7365 | Examples |
| 7366 | -------- |
| 7367 | >>> import pandas as pd |
| 7368 | >>> idx = pd.Index([10.1234, 20.5678, 30.9123, 40.4567, 50.7890]) |
| 7369 | >>> idx.round(decimals=2) |
| 7370 | Index([10.12, 20.57, 30.91, 40.46, 50.79], dtype='float64') |
| 7371 | |
| 7372 | """ |
| 7373 | return self._constructor(self.to_series().round(decimals)) |
| 7374 | |
| 7375 | # -------------------------------------------------------------------- |
| 7376 | # Generated Arithmetic, Comparison, and Unary Methods |