Skip to content

Commit

Permalink
DOC Add documentation for how pandas rounds values in Series.round an…
Browse files Browse the repository at this point in the history
…d Dataframe.round methods (pandas-dev#57981)

add documentation for rounding
  • Loading branch information
marenwestermann authored Mar 24, 2024
1 parent 669ddfb commit 4f145b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10703,6 +10703,12 @@ def round(
numpy.around : Round a numpy array to the given number of decimals.
Series.round : Round a Series to the given number of decimals.
Notes
-----
For values exactly halfway between rounded decimal values, pandas rounds
to the nearest even value (e.g. -0.5 and 0.5 round to 0.0, 1.5 and 2.5
round to 2.0, etc.).
Examples
--------
>>> df = pd.DataFrame(
Expand Down
16 changes: 12 additions & 4 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2509,13 +2509,21 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
numpy.around : Round values of an np.array.
DataFrame.round : Round values of a DataFrame.
Notes
-----
For values exactly halfway between rounded decimal values, pandas rounds
to the nearest even value (e.g. -0.5 and 0.5 round to 0.0, 1.5 and 2.5
round to 2.0, etc.).
Examples
--------
>>> s = pd.Series([0.1, 1.3, 2.7])
>>> s = pd.Series([-0.5, 0.1, 2.5, 1.3, 2.7])
>>> s.round()
0 0.0
1 1.0
2 3.0
0 -0.0
1 0.0
2 2.0
3 1.0
4 3.0
dtype: float64
"""
nv.validate_round(args, kwargs)
Expand Down

0 comments on commit 4f145b3

Please sign in to comment.