In this article, we will discuss getting the ceil and floor values of the Pandas Dataframe. First, Let’s create a dataframe.
Example:
Python3
# importing pandas and numpy import pandas as pd import numpy as np # Creating a DataFrame df = pd.DataFrame({'Student Name': ['Anuj', 'Ajay', 'Vivek', 'suraj', 'tanishq', 'vishal'], 'Marks': [55.3, 82.76, 95.23, 98.12, 95.78, 90.56]}) df |
Output:
Getting the Ceil Value
We can get the ceil value using the ceil() function. Ceil() is basically used to round up the values specified in it. It rounds up the value to the nearest greater integer.
Example:
Python3
# using np.ceil to round to # nearset greater integer for # 'Marks' df['Marks'] = df['Marks'].apply(np.ceil) df |
Output:
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.
Example:
Python3
# using np.floor to # truncate the 'Marks' column df['Marks'] = df['Marks'].apply(np.floor) df |
Output:
Getting the round off value
round() is also used in this purpose only as it rounds off the value according to their decimal digits. Here we can give that to how many decimal places we have to round off our data.
Example:
Python3
# using round() to round up or # down acc. to their decimal digits df['Marks'] = df['Marks'].round(decimals=1) df |
Output:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python | Pandas DataFrame.truncate
- floor() and ceil() function Python
- Python | Pandas dataframe.round()
- Python | Pandas Series.truncate()
- Methods to Round Values in Pandas DataFrame
- Python | Pandas DatetimeIndex.ceil()
- Python | Pandas TimedeltaIndex.ceil
- Python | Pandas Timestamp.ceil
- Python | Pandas Timedelta.ceil()
- Python | Pandas Series.dt.ceil
- Python | Pandas DataFrame.fillna() to replace Null values in dataframe
- Pandas Dataframe.to_numpy() - Convert dataframe to Numpy array
- Convert given Pandas series into a dataframe with its index as another column on the dataframe
- Python | Pandas Series.dt.floor
- Python | Pandas DatetimeIndex.floor()
- Python | Pandas TimedeltaIndex.floor
- Python | Pandas Timestamp.floor
- Python | Pandas Timedelta.floor()
- Python | Truncate a list
- Python | os.truncate() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

