Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floor or ceiling of a pandas series in python?

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.

like image 395
wolfsatthedoor Avatar asked Dec 21 '14 18:12

wolfsatthedoor


People also ask

What is the structure of series in pandas?

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.

How do you use the floor in pandas?

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.

What is floor and ceil in Python?

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.

What is floor in Python?

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.


2 Answers

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.

like image 99
Alex Riley Avatar answered Oct 03 '22 07:10

Alex Riley


I am the OP, but I tried this and it worked:

np.floor(series) 
like image 32
wolfsatthedoor Avatar answered Oct 03 '22 08:10

wolfsatthedoor