我有一个 7300 万行数据集,我需要过滤掉与几个条件中的任何一个匹配的行。我一直在使用布尔索引进行此操作,但这需要很长时间(约 30 分钟),我想知道是否可以使其更快(例如花式索引、np.where、np.compress?)
我的代码:
clean_df = df[~(df.project_name.isin(p_to_drop) |
df.workspace_name.isin(ws_to_drop) |
df.campaign_name.str.contains(regex_string,regex=True) |
df.campaign_name.isin(small_launches))]
正则表达式字符串是
regex_string = '(?i)^.*ARCHIVE.*$|^.*birthday.*$|^.*bundle.*$|^.*Competition followups.*$|^.*consent.*$|^.*DOI.*$|\
^.*experiment.*$|^.*hello.*$|^.*new subscribers.*$|^.*not purchased.*$|^.*parent.*$|\
^.*re engagement.*$|^.*reengagement.*$|^.*re-engagement.*$|^.*resend.*$|^.*Resend of.*$|\
^.*reward.*$|^.*survey.*$|^.*test.*$|^.*thank.*$|^.*welcome.*$'
其他三个条件是少于 50 项的字符串列表。