将列的所有值替换为第一个值-按ID分组

时间:2020-10-04 10:48:17

标签: python pandas

我的熊猫数据框如下:

ID    trackintime               trackouttime            time difference
54    2020-01-01 00:00:03       2020-01-01 00:00:05     00:00:02
55    2020-01-01 00:00:04       2020-01-01 00:00:06     00:00:02
54    2020-01-01 00:00:05       2020-01-01 00:00:10     00:00:05
55    2020-01-01 00:00:06       2020-01-01 00:00:10     00:00:04

我想将每个ID条目的时差值替换为每个ID的第一个条目(时间方向)的时差值。

结果应如下所示:

ID    trackintime               trackouttime            time difference
54    2020-01-01 00:00:03       2020-01-01 00:00:05     00:00:02
55    2020-01-01 00:00:04       2020-01-01 00:00:06     00:00:02
54    2020-01-01 00:00:05       2020-01-01 00:00:10     00:00:02
55    2020-01-01 00:00:06       2020-01-01 00:00:08     00:00:02

在此先感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

GroupBy.transformGroupBy.first一起使用并减去值:

let webView = WKWebView()
    
// ...
// after loading a website with the desired string on it.
// ...
    
webView.find("hello world") { result in
    print(result.matchFound) // true
}