

For example, we can change or extend the built-in functions such as len (), abs (), or divmod () by redefining them in our class.

The ceil () function returns the smallest integer greater than or equal to a number. Overrride Built-in Functions In Python, we can change the default behavior of the built-in functions. %timeit round(series+0.5,0) # 2.99 ms ± 103 µs per loop (mean ± std. The floor () function returns the largest integer less than or equal to a number. %timeit (series+0.5).round(0) # 3.15 ms ± 46.9 µs per loop (mean ± std. The floor function is the part of math module that returns the floor of a given number (x) which is the largest integer number less than or equal to the x. Why astype int works? Because in Python, when converting to integer, that it always get floored.Ĭeil %timeit np.ceil(series) # 1.67 ms ± 21 µs per loop (mean ± std. %timeit series.astype(int) # 2.2 ms ± 131 µs per loop (mean ± std.

series = pd.Series(np.random.normal(100,20,1000000))įloor %timeit np.floor(series) # 1.65 ms ± 18.1 µs per loop (mean ± std. floor() function in python: floor() method in Python returns floor of x i.e., the rounded down integer not greater than x. Here's I provide some alternative to do ceiling and floor using pure pandas and compare it with the numpy approach.
