这是我试过的一段代码。我试图通过将roundtime()函数应用于数据帧“Booking Time”列中的每个条目,将时间四舍五入到最近的小时。但是,舍入不适用于该列,条目保持原样
import datetime as dt
def roundtime(t):
if t.minute >= 30:
return t.replace(second=0, minute=0, hour=(t.hour+1)%24)
else:
return t.replace(second=0, minute=0)
df2= df.copy()
df2['Booking Time']= pd.to_datetime(df2['booking_created']).dt.time
df2['Booking Time'].apply(roundtime)
df2.head()
有人能指出故障吗
如果需要将函数应用于日期时间:
或者,如果需要适用于以下时间:
这可以不用单独的函数来完成
相关问题 更多 >
编程相关推荐