title: Rolling Status from Pandas Dataframe
body: <pre><code>+------+--------+------------+------------+---+---+---+
  | area | locale |    date    |  end date  | i | t | o |
  +------+--------+------------+------------+---+---+---+
  | abc  | abc25  | 2001-03-01 | 2001-04-01 | 1 |   |   |
  | abc  | abc25  | 2001-04-01 | 2001-05-01 | 1 |   |   |
  | abc  | abc25  | 2001-05-01 | 2001-06-01 | 1 |   |   |
  | abc  | abc25  | 2001-06-01 | 2001-07-01 |   | 1 |   |
  | abc  | abc25  | 2001-07-01 | 2001-08-01 |   |   | 1 |
  | abc  | abc25  | 2001-08-01 | 2001-09-01 |   | 1 |   |
  | abc  | abc25  | 2001-09-01 | 2001-05-01 |   | 1 |   |
  | abc  | abc25  | 2001-10-01 | 2001-11-01 |   | 1 |   |
  | abc  | abc25  | 2001-11-01 | 2001-12-01 |   |   | 1 |
  | abc  | abc25  | 2001-12-01 |            |   |   | 1 |
  | def  | def25  | 2001-03-01 | 2001-04-01 |   |   | 1 |
  | def  | def25  | 2001-04-01 | 2001-05-01 |   |   | 1 |
  | def  | def25  | 2001-05-01 | 2001-06-01 |   |   | 1 |
  | def  | def25  | 2001-06-01 | 2001-07-01 |   | 1 |   |
  | def  | def25  | 2001-07-01 | 2001-08-01 |   | 1 |   |
  | def  | def25  | 2001-08-01 | 2001-09-01 | 1 |   |   |
  | def  | def25  | 2001-09-01 | 2001-05-01 | 1 |   |   |
  | def  | def25  | 2001-10-01 | 2001-11-01 |   | 1 |   |
  | def  | def25  | 2001-11-01 | 2001-12-01 |   |   | 1 |
  | def  | def25  | 2001-12-01 |            |   |   | 1 |
  +------+--------+------------+------------+---+---+---+
  </code></pre>
  
  <p>Here is the data table sample that I am working with.  What I am attempting to do is a status column added on here.  The status column is a bit tricky though and here is the criteria:</p>
  
  <ol>
  <li>If any 2 periods of time are the same i/t/o then they get their associated status (let's say R/Y/G)</li>
  <li>If you have two different statuses you choose "best" </li>
  </ol>
  
  <p>Example Output:</p>
  
  <pre><code>+------+--------+------------+------------+---+---+---+--------+
  | area | locale |    date    |  end date  | i | t | o | Status |
  +------+--------+------------+------------+---+---+---+--------+
  | abc  | abc25  | 2001-03-01 | 2001-04-01 | 1 |   |   |  NONE  |
  | abc  | abc25  | 2001-04-01 | 2001-05-01 | 1 |   |   |  R     |
  | abc  | abc25  | 2001-05-01 | 2001-06-01 | 1 |   |   |  R     |
  | abc  | abc25  | 2001-06-01 | 2001-07-01 |   | 1 |   |  Y     |
  | abc  | abc25  | 2001-07-01 | 2001-08-01 |   |   | 1 |  G     |
  | abc  | abc25  | 2001-08-01 | 2001-09-01 |   | 1 |   |  G     |
  | abc  | abc25  | 2001-09-01 | 2001-05-01 |   | 1 |   |  Y     |
  | abc  | abc25  | 2001-10-01 | 2001-11-01 |   | 1 |   |  Y     |
  | abc  | abc25  | 2001-11-01 | 2001-12-01 |   |   | 1 |  G     |
  | abc  | abc25  | 2001-12-01 |            |   |   | 1 |  G     |
  | def  | def25  | 2001-03-01 | 2001-04-01 |   |   | 1 |  NONE  |
  | def  | def25  | 2001-04-01 | 2001-05-01 |   |   | 1 |  G     |
  | def  | def25  | 2001-05-01 | 2001-06-01 |   |   | 1 |  G     |
  | def  | def25  | 2001-06-01 | 2001-07-01 |   | 1 |   |  G     |
  | def  | def25  | 2001-07-01 | 2001-08-01 |   | 1 |   |  Y     |
  | def  | def25  | 2001-08-01 | 2001-09-01 | 1 |   |   |  Y     |
  | def  | def25  | 2001-09-01 | 2001-05-01 | 1 |   |   |  R     |
  | def  | def25  | 2001-10-01 | 2001-11-01 |   | 1 |   |  Y     |
  | def  | def25  | 2001-11-01 | 2001-12-01 |   |   | 1 |  G     |
  | def  | def25  | 2001-12-01 |            |   |   | 1 |  G     |
  +------+--------+------------+------------+---+---+---+--------+
  </code></pre>
  
  <p>Now I looked up pandas rolling, but that might not be the best approach; I tried the following:</p>
  
  <pre><code>df.groupby('locale')['o'].rolling(2).sum()
  </code></pre>
  
  <p>which works on it's own, but I can't seem to create a column out of it so I can say if that == 2 then it is whatever status.  I also tried to just use this in an <code>if</code> statement:</p>
  
  <pre><code>if df.groupby('locale')['o'].rolling(2).sum() == 2.0 : 
      df['locale_status'] = 'Green'
  </code></pre>
  
  <p>this gives an error about the truth value of a series</p>
  
  <p>I also tried :</p>
  
  <pre><code>if df.groupby('locale')['o'] == df.groupby('locale')['o'].shift() : df['test'] = 'Green' 
  </code></pre>
  
  <p>This results in an invalid type comparison.</p>