擅长:python、mysql、java
<p>我知道这已经得到了回答,但我想为将来的任何人提供另一种解决方案:</p>
<p>您可以使用<code>.loc</code>仅通过<code>notnull()</code>的值对数据帧进行子集,然后仅对<code>'x'</code>列进行子集。取同一个载体,然后<code>apply(int)</code>到它上面。</p>
<p><strong>如果x列是浮动的:</strong></p>
<pre><code>df.loc[df['x'].notnull(), 'x'] = df.loc[df['x'].notnull(), 'x'].apply(int)
</code></pre>