python - Pandas - 根据多个 `or` 条件删除行

标签 python pandas

<分区>

假设我的数据框如下所示:

emp_id, age, salary
39239, 32, 2000
11010, 33, 3232
...

我有一个 emp_id 的列表,我想从数据框中删除。该列表超过 200 长,因此多个 过滤器太麻烦了。

是否可以通过仅传递 emp_id 的列表来进行过滤?

最佳答案

使用DataFrame.isin :

df[~df['emp_id'].isin(bad_emp_ids_list)]

关于python - Pandas - 根据多个 `or` 条件删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48068270/

相关文章:

用于自动绑定(bind) __init__ 参数的 Python 装饰器

python - numpy 中不同大小数组的乘积

python - 如何使用 iterrows 通过函数循环数据帧,该函数采用 3 个参数来填充新数据帧

python - 根据 Pandas 中的另一个列值更改列值

python - 根据 Pandas DataFrame 中的元素从另一个 DataFrame 中获取元素

Python BeautifulSoup 相当于 lxml make_links_absolute

python - 覆盖 Bootstrap 不会立即生效

ntp 更新时间时 Python Twisted 应用程序中断

python - 使用 Python 分析大量传感器数据

python - 具有多个特征的 train_test_split