suppose have dataframe in pandas like
c1 c2 0 'ab' 1 1 'ac' 0 2 'bd' 0 3 'fa' 1 4 'de' 0
and want show rows such c1 doesn't contain 'a'. desired output be:
c1 c2 2 'bd' 0 4 'de' 0
my first attempt use df.loc, this:
df.loc['a' not in df['c1']]
for searching specific values, df.loc works fine, searching based on false condition ('a' not in df['c1']) doesn't.
i know can reverse thing. mean, can return rows contain 'a' in column 'c1', through code:
df.loc[df['c1'].str.contains('a')]
but can't figure out elegant/concise way other way around. how can that?
use ~
flip series of booleans:
df.loc[~df['c1'].str.contains('a')]
Comments
Post a Comment