I have a pandas series series
. If I want to get the element-wise floor or ceiling, is there a built in method or do I have to write the function and use apply? I ask because the data is big so I appreciate efficiency. Also this question has not been asked with respect to the Pandas package.
Pandas Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). The axis labels are collectively called index. Pandas Series is nothing but a column in an excel sheet. Labels need not be unique but must be a hashable type.
Getting the floor value We can get the floor value using the floor() function. Floor() is basically used to truncate the values. Basically, it truncates the values to their nearest smaller integer.
The math. floor() method in Python rounds a number down to the nearest integer, if necessary, and returns the output. It is one of the Mathematical functions available in the math library. Likewise, the math. ceil() method in Python returns the ceiling value of the input value.
The floor() function: floor() method in Python returns the floor of x i.e., the largest integer not greater than x. Syntax: import math math. floor(x) Parameter: x-numeric expression. Returns: largest integer not greater than x.
You can use NumPy's built in methods to do this: np.ceil(series)
or np.floor(series)
.
Both return a Series object (not an array) so the index information is preserved.
I am the OP, but I tried this and it worked:
np.floor(series)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With