擅长:python、mysql、java
<p>可以用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_numeric.html" rel="nofollow">^{<cd1>}</a>将类型转换为数值,并传递<code>errors='coerce'</code>,这样就可以得到<code>NaN</code>,因为那些不能转换成数字的。最后,您可以将<code>NaN</code>替换为零:</p>
<pre><code>df["column"] = pd.to_numeric(df["column"], errors="coerce").fillna(0)
Out[15]:
0 0.0
1 20323.0
2 0.0
3 19090.0
4 0.0
5 20474.0
Name: column, dtype: float64
</code></pre>
<p>如果需要整数值,请在末尾添加<code>astype('int64')</code>:</p>
^{pr2}$