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>I think <code>row</code> in your approach is not an row index. It's a row of the DataFrame</p>

<p>You can use this instead:</p>

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

python pandas dataframe