title: fill NaN values of a df under condition
body: <p>I have a resampled df:</p>
  <pre><code>          Timestamp         Loading      Power      Energy      ID      status
  2020-04-09 06:45:00             1.0       1000        5000       1          on
  2020-04-09 06:46:00             1.0       1000        5500       1          on
  2020-04-09 06:47:00             NaN        NaN         NaN     NaN         NaN
  2020-04-09 06:48:00             NaN        NaN         NaN     NaN         NaN
  2020-04-09 06:49:00             1.0          5           0       1         off
  2020-04-09 06:50:00             1.0       3000         200       2          on
  ...
  </code></pre>
  <p>The first thing: df['Loading'] was originally of the type 'boolean' and no its a number (1 or 0) - how can i change this?</p>
  <p>The NaN values of the column df['status'] should simply be continued (last entry was on, then the lines should be filled with on until an off comes).</p>
  <p>Now the other lines of the other columns should be filled differently, depending on whether the status is on or off:</p>
  <p>status == on: loading = 'true'; energy = last existing entry; power = last existing entry; id == last existing entry</p>
  <p>status == off: loading = 'false'; energy = 0; power = 0; Id = 'no ID'.</p>
  <p>i tried something like that:</p>
  <pre><code>cond = (df2['Status'] != df2['Status'].shift(-1)) | (df2['Status'].notna())
  df2.loc[cond] = df2.loc[cond].ffill()
  </code></pre>
  <p>without desired success...</p>
  <p>Expected outcome:</p>
  <pre><code>          Timestamp         Loading      Power      Energy      ID      status
  2020-04-09 06:45:00            True       1000        5000       1          on
  2020-04-09 06:46:00            True       1000        5500       1          on
  2020-04-09 06:47:00            True       1000        5500       1          on
  2020-04-09 06:48:00            True       1000        5500       1          on
  2020-04-09 06:49:00           False          5           0   no Id         off
  2020-04-09 06:49:00            True       3000         200       2          on
  ...
  </code></pre>
  <p><strong>EDIT</strong>
  the condition for filling the nan values is more complicated than expected: I have different cycles which are marked by different IDs. Within a cycle (ID appears both before and after the nan value) the power of the two &quot;surrounding&quot; lines should be averaged and in the column energy the last existing value of the column energy should be entered. Outside the cycle (ID before != next ID) the power as well as the energy should be set to 0.</p>