采用取反的方式~
,带有特定值的行则可以采用等于或者在于的方式,也可同时叠加逻辑运算符
# 采用==筛选特定行
df = df[~(df['name'] == 'Mary')]
df = df[~((df['name'] == 'Mary') & (df['age'] == 18))]
df = df[~((df['name'] == 'Mary') | (df['age'] == 18))]
# 采用isin()筛选特定行
df = df[~df['name'].isin(['Mary','John'])]
df = df[~((df['name'].isin(['Mary','John'])) & (df['age'] == 18))]
df = df[~((df['name'].isin(['Mary','John'])) | (df['age'].isin([14, 18]))]
网友评论