pandas取出包含某个值的所有行

pandas取出包含某个值的所有行
df = df[df[“from_account”].str.contains(“fcwhx”)]

pandas取出不包含某个值的所有行
df = df[~df[“from_account”].str.contains(“fcwhx”,“na=False”)]

df = df[df[“from_account”].str.contains(“fcwhx”)==False]

如果有空值,报错:TypeError: bad operand type for unary ~: ‘float’
则用这个方法
df.other_group = df.other_group.fillna(’####@’)
df2 = df[~df[‘other_group’].str.contains(’####@’)]

不考虑业务场景,一味的争执技术的高下,都是耍流氓。
原文地址:https://www.cnblogs.com/leoych/p/14440279.html