相关疑难解决方法(0)

熊猫:如果多个列中的一个以上为零,则删除行

我有这样一个数据框:

     col0   col1  col2  col3
ID1    0      2     0     2
ID2    1      1     2     10
ID3    0      1     3     4
Run Code Online (Sandbox Code Playgroud)

我想删除包含零个以上的行。

我试着做:

cols = ['col1', etc]
df.loc[:, cols].value_counts()
Run Code Online (Sandbox Code Playgroud)

但这仅适用于系列,不适用于数据帧。

df.loc[:, cols].count(0) <= 1
Run Code Online (Sandbox Code Playgroud)

仅返回布尔值。

我觉得我已经接近第二次尝试了。

python pandas

2
推荐指数
1
解决办法
500
查看次数

标签 统计

pandas ×1

python ×1