GIS之时空数据分析

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]))]
上一篇下一篇

猜你喜欢

热点阅读