检查每个车站的平均出行间隔 - Pyhton
我有以下数据帧结构:
id_trip | dtm_start_trip | dtm_end_trip | start_station | end_station |
---|---|---|---|---|
1 | 2018-10-01 10:15:00 | 2018-10-01 10:17:00 | 100 | 200 |
2 | 2018-10-01 10:17:00 | 2018-10 -01 10:18:00 | 200 | 100 |
3 | 2018-10-01 10:19:00 | 2018-10-01 10:34:00 | 100 | 300 |
4 | 2018-10-01 10:20:00 | 2018-10-01 10:22: 00 | 300 | 100 |
5 | 2018-10-01 10:20:00 | 2018-10-01 10:29:00 | 400 | 400 |
我想使用 python 检查一次旅行在给定季节开始和结束的频率。我们的想法是每天、每小时、然后以几分钟为间隔进行这些平均间隔。
这样做的最佳方法是什么?
我想要的输出是要通知的内容,例如:对于 2018 年 10 月 1 日的车站 100,平均每 4 分钟开始一次旅行
I have the following data frame structure:
id_trip | dtm_start_trip | dtm_end_trip | start_station | end_station |
---|---|---|---|---|
1 | 2018-10-01 10:15:00 | 2018-10-01 10:17:00 | 100 | 200 |
2 | 2018-10-01 10:17:00 | 2018-10-01 10:18:00 | 200 | 100 |
3 | 2018-10-01 10:19:00 | 2018-10-01 10:34:00 | 100 | 300 |
4 | 2018-10-01 10:20:00 | 2018-10-01 10:22:00 | 300 | 100 |
5 | 2018-10-01 10:20:00 | 2018-10-01 10:29:00 | 400 | 400 |
And I would like to check, using python, how often a trip starts and ends in a given season. The idea was to do these average intervals per day, per hour and then in intervals of a few minutes.
What would be the best approach to doing this?
My desired output would be something to inform eg: for station 100 on 2018-10-01, a travel starts, on average, every 4 minutes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先将日期列转换为 Pandas DateTime
First transform the date columns into Pandas DateTime
为此,您可以按不同的行程对 DataFrame 进行分组。首先,我将创建一个包含旅行 ID 的新列,以便可以对在同一车站开始和结束的旅行进行分组。
然后,您可以轻松地按旅行 ID 对这些行进行分组,并获取您需要的所有信息。
请注意,您的数据样本不包含任何“同一行程”。另外,考虑为您的数据提供代码示例,这样我们就可以更轻松地使用和运行测试。
In order to do that you could group your DataFrame by different travels. Firstly, I would make a new column with a travel id, so travels starting and ending in the same stations can be grouped.
Then you can easily group those rows by travel id and get all the information you need.
Please note that your data sample does not include any "same travel". Also, consider providing a code sample for your data, it would be easier for us to work with and run tests.