title: Using specific dataframe cell values to create a consolidated new dataframe
body: <p>So this is an assignment from my python class. We have a dataframe that contains information about a machine. Every minute the machine stands still (as in: no product is being produced for whatever reason) it creates a new row in a dataframe containing the reason. </p>
  
  <p>This is what the first standstill looks like in the DF (text looks weird because I had to translate it from german): </p>
  
  <p><a href="https://i.stack.imgur.com/MCy7g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MCy7g.png" alt="enter image description here"></a></p>
  
  <p>We see that Reason 1 for the standstill started at 2020-03-02 at 14:04 and was rectified at 14:07. </p>
  
  <p>The assignment now is to create a new dataframe to consolidate this information, so that it would look somewhat like this: </p>
  
  <p><a href="https://i.stack.imgur.com/l61w2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l61w2.png" alt="enter image description here"></a></p>
  
  <p>I had the idea to use .shift() in order to check for the beginning and the end of a new Standstillreason. The column "SAP?" (Same as previous?) checks wether the Standstillreason in the current row is the same as in the previous. Same goes for "SAN?" (Same as next?) regarding the next row. </p>
  
  <pre><code>df["SAP?"] = df.Standstillreason.eq(df.Standstillreason.shift())
  df["SAN?"] = df.Standstillreason.eq(df.Standstillreason.shift(periods=-1))
  </code></pre>
  
  <p>Everytime SAP = False, it means that the row contains the start of a new Standstillreason.
  If SAN = False, the row contains the end of the current reason. </p>
  
  <p>What I'm trying to do now is to extract the needed information to put it in the consolidated df. I thought of somewhat like this: </p>
  
  <pre><code>for index, row in df.iterrows(): 
      if row["SAP?"] == False:
          df_consolidated["Standstillreason"] = row["Standstillreason"]
  </code></pre>
  
  <p>But so far this hasn't worked. I'm not even sure wether I'm having the right approach to the problem. </p>