Skip to content

Commit 4f145b3

Browse files
DOC Add documentation for how pandas rounds values in Series.round and Dataframe.round methods (#57981)
add documentation for rounding
1 parent 669ddfb commit 4f145b3

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pandas/core/frame.py

+6
Original file line numberDiff line numberDiff line change
@@ -10703,6 +10703,12 @@ def round(
1070310703
numpy.around : Round a numpy array to the given number of decimals.
1070410704
Series.round : Round a Series to the given number of decimals.
1070510705
10706+
Notes
10707+
-----
10708+
For values exactly halfway between rounded decimal values, pandas rounds
10709+
to the nearest even value (e.g. -0.5 and 0.5 round to 0.0, 1.5 and 2.5
10710+
round to 2.0, etc.).
10711+
1070610712
Examples
1070710713
--------
1070810714
>>> df = pd.DataFrame(

pandas/core/series.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -2509,13 +2509,21 @@ def round(self, decimals: int = 0, *args, **kwargs) -> Series:
25092509
numpy.around : Round values of an np.array.
25102510
DataFrame.round : Round values of a DataFrame.
25112511
2512+
Notes
2513+
-----
2514+
For values exactly halfway between rounded decimal values, pandas rounds
2515+
to the nearest even value (e.g. -0.5 and 0.5 round to 0.0, 1.5 and 2.5
2516+
round to 2.0, etc.).
2517+
25122518
Examples
25132519
--------
2514-
>>> s = pd.Series([0.1, 1.3, 2.7])
2520+
>>> s = pd.Series([-0.5, 0.1, 2.5, 1.3, 2.7])
25152521
>>> s.round()
2516-
0 0.0
2517-
1 1.0
2518-
2 3.0
2522+
0 -0.0
2523+
1 0.0
2524+
2 2.0
2525+
3 1.0
2526+
4 3.0
25192527
dtype: float64
25202528
"""
25212529
nv.validate_round(args, kwargs)

0 commit comments

Comments
 (0)