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)
#import pandasimport pandas as pd# Intialize series without index seriess1 = pd.Series([-2.5, -1.5, 1.5, 2.5])#print Seriesprint("Series 1:")print(s1)# Intialize series with index seriess2 = {'a': 1, 'b': 2, 'c': 3}ser2 = pd.Series(data=s2, index=['a', 'b', 'c'])#print Seriesprint("Series 2:")print(ser2)
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.
# import Pandasimport pandas as pd# Intialize seriess1 =pd.Series([10.5,41.5,52.5,63.5,54.5,55.5,96.5])# print rounded seriesprint(s1.round())
Free Resources