按日期范围分组并检查是否重复 pandas

Group by date range and check duplicate pandas

我想看看能不能找到当年发生的重复记录

我知道如何找到年份,但日期范围并找到重复项并删除重复项似乎有点困难。我是初学者,请问有人能帮忙吗?

您可以使用:

out = df[~df.loc[df['Date'].str.contains('2021')].duplicated(keep=False)
            .reindex(df.index, fill_value=False)]
print(out)

# Output
         Date Transaction
0  31/12/2020   PURCHASES
1  31/12/2020       Sales
2  31/12/2020       Sales