How to test for nan's in an apply function in pandas?
<p>I have a simple <code>apply</code> function that I execute on some of the columns.  But, it keeps getting tripped up by <code>NaN</code> values in <code>pandas</code>.  </p>

<pre><code>input_data = np.array(
[
[random.randint(0,9) for x in range(2)]+['']+['g'],
[random.randint(0,9) for x in range(3)]+['g'],
[random.randint(0,9) for x in range(3)]+['a'],
[random.randint(0,9) for x in range(3)]+['b'],
[random.randint(0,9) for x in range(3)]+['b']
]
)

input_df = pd.DataFrame(data=input_data, columns=['B', 'C', 'D', 'label'])
</code></pre>

<p>I have a simple lambda like this:</p>

<pre><code>input_df['D'].apply(lambda aCode: re.sub('\.', '', aCode) if not np.isnan(aCode) else aCode)
</code></pre>

<p>And it gets tripped up by the NaN values:</p>

<pre><code>File "&lt;pyshell#460&gt;", line 1, in &lt;lambda&gt;
    input_df['D'].apply(lambda aCode: re.sub('\.', '', aCode) if not np.isnan(aCode) else aCode)
TypeError: Not implemented for this type
</code></pre>

<p>So, I tried just testing for nan values that Pandas adds:</p>

<pre><code>np.isnan(input_df['D'].values[0])
np.isnan(input_df['D'].iloc[0])
</code></pre>

<p>Both get the same error.</p>

<p>I do not know how to test for nan values other than <code>np.isnan</code>.  Is there an easier way to do this?  Thanks.</p>