Pandas DataFrame 删除带有特定值的行
2020-12-17 本文已影响0人
王叽叽的小心情
采用取反的方式~
,带有特定值的行则可以采用等于或者在于的方式,也可同时叠加逻辑运算符
# 采用==筛选特定行
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]))]