【发布时间】:2018-04-30 16:15:10
【问题描述】:
我有一个这样的数据框:
Subject Verb Object Date
---------------------------------
Bill Ate Food 7/11/2015
Steve Painted House 8/12/2011
Bill Ate Food 7/13/2015
Steve Painted House 8/25/2011
我想删除所有重复项,其中重复项被定义为具有相同的主语、动词、宾语,并且在 X 天范围内(在我的示例中:5 天)。
Subject Verb Object Date
---------------------------------
Bill Ate Food 7/11/2015
Steve Painted House 8/12/2011
Steve Painted House 8/25/2011
两个“Steve - Painted - House”实例都没有被删除,因为它们超出了 5 天的窗口期。
我知道我可以使用一些数据结构和 DataFrame 的 iterrows 方法来做到这一点,但是有没有办法使用 Pandas drop_duplicates 做到这一点?
【问题讨论】:
标签: python pandas dataframe duplicates