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(’####@’)]