[英]What is the fastest way to select rows that contain a value in a Pandas dataframe?
[英]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.