【发布时间】:2017-05-24 16:29:33
【问题描述】:
我在下面有一个数据框表,其中包含新值和旧值。我想删除所有旧值,同时保留新值。
ID Name Time Comment
0 Foo 12:17:37 Rand
1 Foo 12:17:37 Rand1
2 Foo 08:20:00 Rand2
3 Foo 08:20:00 Rand3
4 Bar 09:01:00 Rand4
5 Bar 09:01:00 Rand5
6 Bar 08:50:50 Rand6
7 Bar 08:50:00 Rand7
因此它应该是这样的:
ID Name Time Comment
0 Foo 12:17:37 Rand
1 Foo 12:17:37 Rand1
4 Bar 09:01:00 Rand4
5 Bar 09:01:00 Rand5
我尝试使用下面的代码,但这会删除 1 个新值和 1 个旧值。
df[~df[['Time', 'Comment']].duplicated(keep='first')]
谁能提供正确的解决方案?
【问题讨论】:
标签: python datetime pandas dataframe