您可以将
boolean indexing和条件一起使用
isin,
Series通过
~以下方式反转布尔值:
import pandas as pdUSERS = pd.Dataframe({'email':['[email protected]','[email protected]','[email protected]','[email protected]','[email protected]']})print (USERS) email0 [email protected] [email protected] [email protected] [email protected] [email protected] = pd.Dataframe({'email':['[email protected]','[email protected]']})print (EXCLUDE) email0 [email protected] [email protected] (USERS.email.isin(EXCLUDE.email))0 True1 False2 False3 False4 TrueName: email, dtype: boolprint (~USERS.email.isin(EXCLUDE.email))0 False1 True2 True3 True4 FalseName: email, dtype: boolprint (USERS[~USERS.email.isin(EXCLUDE.email)]) email1 [email protected] [email protected] [email protected]
另一个解决方案
merge:
df = pd.merge(USERS, EXCLUDE, how='outer', indicator=True)print (df) email _merge0 [email protected] both1 [email protected] left_only2 [email protected] left_only3 [email protected] left_only4 [email protected] bothprint (df.loc[df._merge == 'left_only', ['email']]) email1 [email protected] [email protected] [email protected]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)