How to handle non-numeric entries in an integer valued column
<p>I have a dataframe <code>df</code> and one of the columns <code>count</code> is contains strings. These strings are mostly convertable to integers (e.g. <code>0006</code>) which is what I will do with them. However some of the entries in <code>count</code> are blank strings of spaces. How can I </p>

<ul>
<li>Drop all the rows where the <code>count</code> value is a blank string.</li>
<li>Substitute all the blank values in that column with some numeric value of my choice.</li>
</ul>

<p>The dataframe is very large if there are particularly efficient ways of doing this.</p>

<p>It seems that you want two different things. But first, convert column <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_numeric.html#pandas.to_numeric" rel="nofollow">to numeric</a> and coerce errors:</p>

<pre><code>df['count'] = pd.to_numeric(df['count'], errors='coerce')
</code></pre>

<p>To drop rows (use <code>subset</code> to avoid dropping <code>NaN</code> from other columns):</p>

<pre><code>df.dropna(subset=['count'])
</code></pre>

<p>To replace with default value:</p>

<pre><code>df['count'] = df['count'].fillna(default_value)
</code></pre>

python pandas