擅长:python、mysql、java
<p>您可以使用<code>pd.dropna</code>,但不使用<code>how='all'</code>和<code>subset=[]</code>,您可以使用<code>thresh</code>参数在删除行之前要求行中的NAs最少数量。在城市中,long/lat示例中,<code>thresh=2</code>将起作用,因为我们只在3个NAs的情况下下降。使用MaxU建立的伟大数据示例,我们可以</p>
<pre><code>## get the data
df = pd.read_clipboard()
## remove undesired rows
df.dropna(axis=0, subset=[['city', 'longitude', 'latitude']], thresh=2)
</code></pre>
<p>这将产生:</p>
<pre><code>In [5]: df.dropna(axis=0, subset=[['city', 'longitude', 'latitude']], thresh=2)
Out[5]:
city latitude longitude a b
0 aaa 11.1111 NaN 1 2
1 bbb NaN 22.2222 5 6
3 NaN 11.1111 33.3330 1 2
</code></pre>