擅长:python、mysql、java
<pre><code>t = df.checkVar.dropna().astype(str).str[0].astype(int) #get a series of the first digits of non-nan numbers
df['newVar'] = ((t > 5) | (t < 2)).astype(int)
df.newVar = df.newVar.fillna(0)
</code></pre>
<p>这可能稍微好一点,不确定,但另一个,非常相似的方法来处理它。在</p>
^{pr2}$