Floor or ceiling of a pandas series in python?

wolfsatthedoor picture wolfsatthedoor · Dec 21, 2014 · Viewed 69.3k times · Source

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.

Answer

Alex Riley picture Alex Riley · Dec 21, 2014

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.