title: How to 'unravel' a dataframe using the values of the rows?
body: <p>I have a <code>DataFrame</code> that looks like this:</p>
  
  <pre><code>class    passed       failed           extra_teaching
  A11      1            2                0.5
  A12      2            1                0.7
  </code></pre>
  
  <p>I want to 'unravel' the <code>DataFrame</code>, and lose the information about the class but keep the information on <code>extra_teaching</code>, so I end up with a row for each individual pupil who passed. </p>
  
  <p>So the <code>DataFrame</code> should end up looking like this:</p>
  
  <pre><code>pass           extra_teaching
  1              0.5
  0              0.5 
  0              0.5
  1              0.7
  1              0.7
  0              0.7
  </code></pre>
  
  <p>I have no idea how to do this in <code>pandas</code>, except perhaps by using <code>iterrows()</code> and manually appending rows to a new <code>DataFrame</code> - has anyone got a neater way?</p>
  
  <p>UPDATE:</p>
  
  <p>I tried this, seems to work though not very elegant:</p>
  
  <pre><code>temp = []
  df = df.set_index('class')
  for idx in df.index:
      row = df.loc[idx]
      t = {'class': idx, 'extra_teaching': row['extra_teaching']}
      for i in range(0, int(row['passed'])):
          t['pass'] = 1
          temp.append(t)
      for i in range(0, int(row['failed'])):
          t['pass'] = 0
          temp.append(t)
  df_exploded = pd.DataFrame(temp)
  </code></pre>