python - Pandas analogue of SQL's "NOT IN" operator -
suprisingly, can't find analogue of sql's "not in" operator in pandas dataframes.
a = pd.dataframe({'a':[6,8,3,9,5], 'b':['ii','i','i','iii','ii']}) b = pd.dataframe({'c':[1,2,3,4,5]}) i want rows a, a doesn't contain values b's c. like:
a = a[ a.a not in b.c]
i think close - need isin ~ negate boolean mask - instead list use series b.c:
print (~a.a.isin(b.c)) 0 true 1 true 2 false 3 true 4 false name: a, dtype: bool = a[~a.a.isin(b.c)] print (a) b 0 6 ii 1 8 3 9 iii
Comments
Post a Comment