放下它们:
nms.dropna(thresh=2)
这将删除所有至少有两个non-的行NaN
。
然后,您可以将名称放在哪里NaN
:
In [87]:
nms
Out[87]:
movie name rating
0 thg John 3
1 thg NaN 4
3 mol Graham NaN
4 lob NaN NaN
5 lob NaN NaN
[5 rows x 3 columns]
In [89]:
nms = nms.dropna(thresh=2)
In [90]:
nms[nms.name.notnull()]
Out[90]:
movie name rating
0 thg John 3
3 mol Graham NaN
[2 rows x 3 columns]
实际查看您最初想要的是什么,而无需dropna
调用即可:
nms[nms.name.notnull()]
3年后的这个问题,有一个错误,首先thresh
arg至少查找n
非NaN
值,因此实际上输出应为:
In [4]:
nms.dropna(thresh=2)
Out[4]:
movie name rating
0 thg John 3.0
1 thg NaN 4.0
3 mol Graham NaN
我可能是3年前弄错了,或者我运行的熊猫版本存在错误,这两种情况都是可能的。