繁体   English   中英

选择字符串列的值在集合中的行的最快方法

[英]Fastest way to select rows where value of column of strings is in a set

我有一set从一组值中选择的电子邮件地址。 我想对pandas DataFrame进行子集pandas DataFrame以仅包含集合中不包含unique_id列值的行。 这是我所做的运行速度很慢的事情:

signup_emails = set(online_signup.unique_id)
non_email_signup_event_emails = event_attendees[event_attendees.unique_id.apply(lambda x: x in signup_emails) == False].email

该表有几十万行,但我的计算机只是在执行此命令时冻结,显示 CPU 负载很高,并且即使经过长时间等待(20 分钟)也不会终止。 我怎样才能更快地做到这一点?

使用isin方法。

event_attendees[event_attendees.isin(signup_emails)]

对于不在 signup_emails 中,您可以执行

event_attendees[event_attendees.isin(signup_emails) == False]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM