Ceil and floor of the dataframe in Pandas Python – Round up and Truncate
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 # nearest 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:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2018-08-03 nginx location静态文件配置