栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在熊猫滚动窗口中基于多个列查找重复项?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在熊猫滚动窗口中基于多个列查找重复项?

所以我使它工作,但不支持滚动窗口,因为它不支持字符串类型。该功能也在Pandas Repo上进行了报告和请求。

我对这个问题的解决方案摘要:

    if len(df.index) > 0:        res = df.loc[(df.merchant == data['transaction']['merchant']) & (df.amount == data['transaction']['amount'])]        res['timediff'] = (data['transaction']['time'] - res['time']).dt.total_seconds().abs() <= 120        if res.timediff.any(): continue    df = df.append(df1)print(df)

样本数据:

{"transaction": {"merchant": "merchantA", "amount": 20, "time": "2019-02-13T10:00:00.000Z"}}{"transaction": {"merchant": "merchantB", "amount": 90, "time": "2019-02-13T11:00:01.000Z"}}{"transaction": {"merchant": "merchantC", "amount": 10, "time": "2019-02-13T11:00:10.000Z"}}{"transaction": {"merchant": "merchantD", "amount": 10, "time": "2019-02-13T11:00:20.000Z"}}{"transaction": {"merchant": "merchantE", "amount": 10, "time": "2019-02-13T11:01:30.000Z"}}{"transaction": {"merchant": "merchantF", "amount": 10, "time": "2019-02-13T11:03:00.000Z"}}{"transaction": {"merchant": "merchantE", "amount": 10, "time": "2019-02-13T11:02:00.000Z"}}{"transaction": {"merchant": "merchantF", "amount": 10, "time": "2019-02-13T11:02:20.000Z"}}{"transaction": {"merchant": "merchantE", "amount": 10, "time": "2019-02-13T11:02:30.000Z"}}{"transaction": {"merchant": "merchantF", "amount": 10, "time": "2019-02-13T11:05:20.000Z"}}{"transaction": {"merchant": "merchantE", "amount": 10, "time": "2019-02-13T11:00:30.000Z"}}

输出:

merchant  amount     time2019-02-13 10:00:00  merchantA      20 2019-02-13 10:00:002019-02-13 11:00:01  merchantB      90 2019-02-13 11:00:012019-02-13 11:00:10  merchantC      10 2019-02-13 11:00:102019-02-13 11:00:20  merchantD      10 2019-02-13 11:00:202019-02-13 11:01:30  merchantE      10 2019-02-13 11:01:302019-02-13 11:03:00  merchantF      10 2019-02-13 11:03:002019-02-13 11:05:20  merchantF      10 2019-02-13 11:05:20


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668610.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号