【发布时间】:2023-03-14 21:01:01
【问题描述】:
df.head(10).to_clipboard(sep=';', index=True)
我有一个如上所述的数据框,并且我有以下列描述
• Id - the uuid of this delivery
• PlanId - the uuid of the plan (the plan for deliveries of a given day)
• PlanDate - the date of delivery
• MinTime - the minimal time (seconds from midnight) for delivering this delivery
• MaxTime - the maximal time (seconds from midnight) for delivering this delivery
• RouteId - the uuid of the route this delivery belongs to
• ETA - the estimated time for arrival of this delivery on this date (from the eta you can of course order the deliveries in a route)
• TTN - the time to next delivery in the route, i.e., at index 3 that would be the time distance between delivery index 3 and delivery index 4
• DTN - the distance to next delivery in the route.
我需要找到给定计划中每条路线的交货中位数。
给定计划中每条路线行驶的中位距离。
给定计划中每条路线的平均行驶时间。
我该怎么做?
我想知道这是否只是简单地计算中位数,您只需按分组和聚合 我试过这样的方法来找到中间距离
Tx = df.groupby(by=['plan_id','route_id'], as_index=False)['dtn'].sum()
Tx.groupby(['plan_id','route_id'])['dtn'].median()
但是我可能不确定这是否正确。
【问题讨论】:
-
请以文本格式提供示例数据。无法通过图像数据重现示例。
标签: python pandas pandas-groupby