用于过滤字符串:
df = df[(df != 'p').all(axis=1)]
比较不等于:
print ((df != 'p'))
A B C
0 True True True
1 True True True
2 True True False
3 True False True
并对所有人进行测试True
每行 s:
print ((df != 'p').all(axis=1))
0 True
1 True
2 False
3 False
dtype: bool
Or:
df = df[~(df == 'p').any(axis=1)]
测试是否相等:
print ((df == 'p'))
A B C
0 False False False
1 False False False
2 False False True
3 False True False
测试至少一项True
每行:
print ((df == 'p').any(axis=1))
0 False
1 False
2 True
3 True
dtype: bool
反转布尔掩码:
print (~(df == 'p').any(axis=1))
0 True
1 True
2 False
3 False
dtype: bool
用于过滤子字符串使用contains http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.contains.html with apply
:
df = df[~df.apply(lambda x: x.astype(str).str.contains('p')).any(axis=1)]
Or:
df = df[~df.stack().astype(str).str.contains('p').unstack().any(axis=1)]
print (df)
A B C
0 1 a x
1 w g n