Search⌘ K
AI Features

The round() Function with a Pandas Series

Explore how to use the round() function with pandas Series, focusing on the specifics of bankers' rounding in Python 3. Understand the differences in rounding .5 values to improve data accuracy in pandas.

We'll cover the following...

Try it yourself

Try executing the code below to see the result.

Python 3.5
import pandas as pd
s = pd.Series([-2.5, -1.5, -0.5, 0.5, 1.5, 2.5])
print(s.round())

Explanation

Rounding is easy most of the time. For example, round(1.1) evaluates to 1 and round(1.8) ...