如果行中的任何值等于零,则将其删除到 pandas 数据框中 [英] Drop row in pandas dataframe if any value in the row equals zero

查看:53
本文介绍了如果行中的任何值等于零,则将其删除到 pandas 数据框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果行中的任何值等于零,如何删除行?

How do I drop a row if any of the values in the row equal zero?

我通常将df.dropna()用于NaN值,但不确定如何使用"0"值.

I would normally use df.dropna() for NaN values but not sure how to do it with "0" values.

推荐答案

我认为最简单的方法是查看所有值都不等于0的行:

i think the easiest way is looking at rows where all values are not equal to 0:

df[(df != 0).all(1)]

这篇关于如果行中的任何值等于零,则将其删除到 pandas 数据框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆