Convert string based NaN's to numpy NaN's
<p>I have a dataframe with a part of it shown as below:</p>

<pre><code>2016-12-27              NaN
2016-12-28              NaN
2016-12-29              NaN
2016-12-30              NaN
2016-12-31              NaN
Name: var_name, dtype: object
</code></pre>

<p>The column contains NaN as strings/objects. How can I convert it to a numpy nan instead. Best would be able to do so when I read in the csv file.</p>

<p>I'd use the <code>converters</code> option in <code>read_csv</code>.  In this case, we are aiming to convert the column in question to numeric values and treat everything else as <code>numpy.nan</code> which includes string version of <code>'NaN'</code></p>

<pre><code>converter = lambda x: pd.to_numeric(x, 'coerce')
df = pd.read_csv(StringIO(txt), delim_whitespace=True, converters={1: converter}, header=None)
df
</code></pre>

<p><a href="http://i.stack.imgur.com/mPA8c.png" rel="nofollow"><img src="http://i.stack.imgur.com/mPA8c.png" alt="enter image description here"></a></p>

<pre><code>df.dtypes

0     object
1    float64
dtype: object
</code></pre>

python pandas numpy