Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

panda series

How does the round function work with pandas series?

Educative Team

Pandas series

Pandas series is a one-dimensional array that can hold all types of Python objects. A pandas series is like a column in a table.

class pandas.Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False)
Pandas series
#import pandas 
import pandas as pd
# Intialize series without index series
s1 = pd.Series([-2.5, -1.5, 1.5, 2.5])
#print Series
print("Series 1:")

# Intialize series with index series
s2 = {'a': 1, 'b': 2, 'c': 3}
ser2 = pd.Series(data=s2, index=['a', 'b', 'c'])
#print Series
print("Series 2:")
Overview of pandas series

Rounding in pandas series

Rounding is a simple concept. In Round(1.x), if x is less than 5, then it will be 1.0 and if x is greater than 5, then it will be 2.0. However, the main concern is what we do if x is equal to 5. Should we round it up or down?

In such a case, pandas checks for a digit before the decimal point. If it is an odd number, then it rounds up the number and if it is an even number, it rounds down the number. This is called bankers’ rounding.

Working of the Round() function
# import Pandas 
import pandas as pd
# Intialize series 
s1 =pd.Series([10.5,41.5,52.5,63.5,54.5,55.5,96.5])
# print rounded series
Overview of the Round() function


panda series
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring