title: iterate column value based on repeating range in next column pandas
body: <p>I have a spreadsheet that represents a network switch. The first row for each switch are the odd ports, beneath that are the destination ports for each of those switch ports, beneath that are the even ports, and beneath that are the destination ports for each of the even ports. So, 4 rows of information, the first and third representing switch ports, the second and third rows are their respective destinations. I have manipulated this data into columns, and as the ports repeat (moving to the next switch, ports 1-36) I need to iterate the name of these switches as we move down the column, so next time it sees port 1, it needs to pull the name of the new switch for all rows that belong to that switch and add the name in the new column.</p>
  
  <p>I've got everything squared away with the exception figuring out how to have pandas know that the series has started over, and it's time to iterate to this new switch name, which is pulled from the same spreadsheet.</p>
  
  <p>I don't even know where to begin and haven't found a good example. Current state for first three lines:</p>
  
  <pre><code>0    1     Rx  LEAF A   Px  
  1    3     Rx  LEAF B   Px  
  2    5     Rx  LEAF A   Px  
  </code></pre>
  
  <p>When this series repeats and you see a '1' in the second column again, I need to iterate to the next switch name, we'll call the switch list: A1, A2, A3, for example, so desired output for first switch:</p>
  
  <pre><code>0    A1  1     Rx  LEAF A   Px  
  1    A1  3     Rx  LEAF B   Px  
  2    A1  5     Rx  LEAF A   Px  
  </code></pre>
  
  <p>Second switch:</p>
  
  <pre><code>0    A2  1     Rx  LEAF A   Px  
  1    A2  3     Rx  LEAF B   Px  
  2    A2  5     Rx  LEAF A   Px  
  </code></pre>
  
  <p>Third Switch:</p>
  
  <pre><code>0    A3  1     R1  LEAF A   Px  
  1    A3  3     R1  LEAF B   Px  
  2    A3  5     R6  LEAF A   Px  
  </code></pre>
  
  <p>Any help would be greatly appreciated. I'm just beginning with Python and Pandas, and have hit a roadblock, even after a couple days of search.Thanks!</p>