大家好,我正在尝试将我的SQL server查询转换为pandasql
因此,任务是获取两个进程之间的平均时间(以分钟为单位
这是我对SQL server的查询。
select payment_method,cast(avg(cast(cast(DATEDIFF(second,booking_created_time,booking_paid_time) as float)/60 as float)) as decimal(20,2)) as difference_minute
from fact_flight_sales
group by payment_method
该查询返回十进制形式,因此代码将返回小于1分钟的每个十进制平均值
这是我在pandasql上的代码
q2 = """
select payment_method,booking_created_time,booking_paid_time,(booking_created_time-booking_paid_time)
from dffact_flight_sales
group by payment_method
"""
print(sqldf(q2, locals()))
pandas SQL只返回日期差异,而不返回小时和分钟。如何进行查询?是否与我的SQL server查询完全相同?
发布于 2021-10-07 05:19:53
import pandas as pd
dffact_flight_sales = pd.read_csv(r"C:\Users\lixfe\Desktop\fact_flight_sales.csv")
dffact_flight_sales['time difference'] = ((pd.to_datetime(dffact_flight_sales['booking_paid_time']) -
pd.to_datetime(dffact_flight_sales['booking_created_time']))
.dt.total_seconds() / 60)
GK = dffact_flight_sales.groupby('payment_method')
GK1 = GK[['payment_method','time difference']]
GK1.first()
https://stackoverflow.com/questions/69455418
复制相似问题