To find the ceiling of numbers in a column using pandas, the easiest way is to use the numpy ceil() function.

df["Column"] = df["Column"].apply(np.ceil)

Finding the ceiling of numbers in a column in pandas is easy. We can round up numbers in a column to the nearest integer with the numpy ceil() function.

Let’s say we have the following DataFrame.

df = pd.DataFrame({'Name': ['Jim', 'Sally', 'Bob', 'Sue', 'Jill', 'Larry'],
                   'Weight': [160.20, 123.81, 209.45, 150.35, 102.43, 187.52]})

print(df)
# Output: 
    Name  Weight
0    Jim  160.20
1  Sally  123.81
2    Bob  209.45
3    Sue  150.35
4   Jill  102.43
5  Larry  187.52

To get the ceiling of the numbers in the column “weight”, we can apply the numpy ceil() function in the following way:

df["Ceiling of Weight"] = df["Weight"].apply(np.ceil)

print(df)

# Output:
    Name  Weight  Ceiling of Weight
0    Jim  160.20              161.0
1  Sally  123.81              124.0
2    Bob  209.45              210.0
3    Sue  150.35              151.0
4   Jill  102.43              103.0
5  Larry  187.52              188.0

If you are looking to find the ceiling of a number in regular Python, you can use the Math.ceil() function.

If you want to round down a column to the nearest integer, instead of rounding up, you can use the numpy floor() function.

Hopefully this article has been helpful for you to use the numpy ceil() function to find the ceiling of numbers in a column using pandas in python.

Categorized in:

Python,

Last Update: February 26, 2024