用圈时间创建列给定的总时间
我有四个不同的人,每个人都跑了,我需要为每个人计算每个圈的圈速。从一开始,我就可以从每圈结束时从一开始就获得了总的时间。我可以使用哪种类型的pyspark/sql/pandas语法有效地计算圈速?
示例:
每行代表一个跑步一圈的人。
persyid | 总时间经过(SEC) | 圈时间(SEC) |
---|---|---|
1 | 200 | 200 |
1 | 300 | 1 100 |
1 | 550 | 250 |
2 | 100 1 | 100 |
2 | 150 250 | 100 |
2 | 250 | 150 |
3 | 150 | 150 |
3 | 500 | 350 |
4 | 100 | 100 4 100 |
4 | 100 4 300 | 200 |
4 | 350 | 50 |
4 | 460 | 110 |
我只需要使用前两列创建第三列,圈时间。我可以写一个最终有效的循环,但是到达那里的最佳/高效pyspark/sql/pandas的方法是什么?
I have four different people, each run laps and I need to calculate lap time for each lap for each person. I am given the total elapsed time starting from the very beginning at the end of each lap. What kind of PySpark/SQL/Pandas syntax could I use to calculate lap times efficiently?
Example:
Each row represents one person running one lap.
PersonID | Total Time Elapsed (sec) | Lap Time (sec) |
---|---|---|
1 | 200 | 200 |
1 | 300 | 100 |
1 | 550 | 250 |
2 | 100 | 100 |
2 | 150 | 50 |
2 | 250 | 100 |
3 | 150 | 150 |
3 | 500 | 350 |
4 | 100 | 100 |
4 | 300 | 200 |
4 | 350 | 50 |
4 | 460 | 110 |
I need to create the 3rd column, Lap Time, using only the first two columns. I could write a for loop that would eventually work but what is the best/efficient PySpark/SQL/Pandas way to get there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
窗口功能可以做到。
pyspark:
sql:
Window functions could do it.
PySpark:
SQL:
如果您正在寻找熊猫解决方案,其中一种方法可能是:
If you are looking for a pandas solution, one of the approaches could be: