擅长:python、mysql、java
<p>这是从<a href="https://stackoverflow.com/questions/13445241/replacing-blank-values-white-space-with-nan-in-pandas">this, more thorough question</a>修改的答案。我会让它更像Python,解决你的问题。</p>
<pre><code>def ws_to_zero(maybe_ws):
try:
if maybe_ws.isspace():
return 0
else:
return maybe_ws
except AttributeError:
return maybe_ws
d.applymap(ws_to_zero)
</code></pre>
<p>其中<code>d</code>是您的数据帧。</p>