Do something to every row on a pandas dataframe
<p>Im trying to do something to a pandas dataframe as follows:</p>

<p>If say row 2 has a 'nan' value in the 'start' column, then I can replace all row entries with '999999'</p>

<pre><code>if pd.isnull(dfSleep.ix[2,'start']):
    dfSleep.ix[2,:] = 999999
</code></pre>

<p>The above code works but I want to do it for every row, ive tried replacing the '2' with a ':' but that does not work</p>

<pre><code>if pd.isnull(dfSleep.ix[:,'start']):
    dfSleep.ix[:,:] = 999999
</code></pre>

<p>and ive tried something like this</p>

<pre><code>for row in df.iterrows():
    if pd.isnull(dfSleep.ix[row,'start']):
        dfSleep.ix[row,:] = 999999
</code></pre>

<p>but again no luck, any ideas?</p>

<p>UPDATE:</p>

<pre><code>In [63]: df
Out[63]:
   a  b    c
0  0  3  NaN
1  3  7  5.0
2  0  5  NaN
3  4  1  6.0
4  7  9  NaN

In [64]: df.ix[df.c.isnull()] = [999999] * len(df.columns)

In [65]: df
Out[65]:
        a       b         c
0  999999  999999  999999.0
1       3       7       5.0
2  999999  999999  999999.0
3       4       1       6.0
4  999999  999999  999999.0
</code></pre>

<p>You can use vectorized approach (<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.fillna.html" rel="nofollow">.fillna()</a> method):</p>

<pre><code>In [50]: df
Out[50]:
   a  b    c
0  1  8  NaN
1  8  8  6.0
2  5  2  NaN
3  9  4  1.0
4  4  2  NaN

In [51]: df.c = df.c.fillna(999999)

In [52]: df
Out[52]:
   a  b         c
0  1  8  999999.0
1  8  8       6.0
2  5  2  999999.0
3  9  4       1.0
4  4  2  999999.0
</code></pre>

python pandas dataframe