title: Looping through a python pivot table
body: <p>I have a pivot table that I have created (pivotTable) using:</p>
  <pre><code>pivotTable= dayData.pivot_table(index=['sector'], aggfunc='count')
  </code></pre>
  <p>which has produced the following pivot table:</p>
  <pre><code>                   sector id  
  broad_sector                            
  Communications         2   2 
  Utilities              3   3
  Media                  3   3
  </code></pre>
  <p>Could someone just let me know if there is a way to loop through the pivot table assigning the index value and sector total to respective variables <code>sectorName</code> and <code>sectorCount</code></p>
  <p>I have tried:</p>
  <pre><code>i=0
  while i &lt;= lenPivotTable:
      sectorName = sectorPivot.index.get_level_values(0)
      sectorNumber = sectorPivot.index.get_level_values(1)
      i=i+1 
  </code></pre>
  <p>to return for the first loop iteration:</p>
  <pre><code>sectorName = 'Communications'
  sectorCount = 2
  </code></pre>
  <p>for the second loop iteration:</p>
  <pre><code>sectorName = 'Utilities'
  sectorCount = 3
  </code></pre>
  <p>for the third loop iteration:</p>
  <pre><code>sectorName = 'Media'
  sectorCount = 3
  </code></pre>
  <p>But can't get it to work.</p>