在Pandasq中以小时为单位计算日期时间差

2024-04-20 09:53:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望datetime类型列(date)的差值以小时为单位表示为十进制(0.001、0.2等) 我尝试使用pandasql库的sqldf来使用SQL查询,但是我只能看到0作为输出。 我试过的代码是:

    temp="""select 
id1,id2,(max(date)- 
 min(date))/3600 as hours from df 
 group by 1,2"""
 Dfhours=ps.sqldf(temp,locals())

id是int64类型,date是datetime64[ns]类型。我也尝试使用DATADIFF,但没有帮助


Tags: 代码类型sqldatetimedate单位selecttemp