np.isin公司()返回重复结果

2024-04-19 08:31:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过比较数据帧和np.数组. 使用user_id=1它可以正确过滤。但是user_id=8它给了我重复。为什么?你知道吗

我的np.数组usedUserArticlesIds=

array([[1202623831,          1]], dtype=int64)

我的DataFrame dfUserArticles:

user_id article_id  date_saved
2   1   1202623831  2019-05-09 10:46:20
23  1   1127087222  2019-01-03 21:33:46
31  8   823279599   2019-05-20 13:42:16
32  8   327321877   2019-05-20 13:42:16
33  8   590862779   2019-05-20 13:42:15
34  8   2341781293  2019-05-20 13:41:55

dfUserArticles = dfUserArticles[~np.isin(dfUserArticles[['user_id', 'article_id']], usedUserArticlesIds)]

输出:

    user_id article_id  date_saved
23  1   1127087222  2019-01-03 21:33:46
31  8   823279599   2019-05-20 13:42:16
31  8   823279599   2019-05-20 13:42:16
32  8   327321877   2019-05-20 13:42:16
32  8   327321877   2019-05-20 13:42:16
33  8   590862779   2019-05-20 13:42:15
33  8   590862779   2019-05-20 13:42:15
34  8   2341781293  2019-05-20 13:41:55
34  8   2341781293  2019-05-20 13:41:55

预期产量:

user_id article_id  date_saved
23  1   1127087222  2019-01-03 21:33:46
31  8   823279599   2019-05-20 13:42:16
32  8   327321877   2019-05-20 13:42:16
33  8   590862779   2019-05-20 13:42:15
34  8   2341781293  2019-05-20 13:41:55

Tags: 数据iddataframedatenparticle数组array