title: Pandas: how to create a running count column?
body: <p>I have a flat text file of the form (column headers added by me)</p>
  
  <pre><code>CASE        Diagnosis
    S1 no diagnosis
    S2 fungus
       squamous lesion
    S3 fungus
    S4 squamous lesion
       glandular lesion
       atypia
  </code></pre>
  
  <p>I would like to stack and unstack cases with multiple diagnoses, so I would like</p>
  
  <pre><code>CASE DxN         Diagnosis
    S1 A   no diagnosis
    S2 A   fungus   
       B   squamous lesion
    S3 A   fungus
    S4 A   squamous lesion
       B   glandular lesion
       C   atypia
  </code></pre>
  
  <p>and</p>
  
  <pre><code>CASE                 A                 B       C
    S1 no diagnosis
    S2 fungus             squamous lesion
    S3 fungus
    S4 squamous lesion    glandular lesion  atypia
  </code></pre>
  
  <p>how do I make that subseries DxN? The count should never be greater than F. Even if there were 10,000 possible answers, there is never more than 6 per case, so no more than 6 columns. I just want "What is diagnosis A for case S1, what's diagnosis B for case S1, what's diagnosis 3 for case S1?" I don't want a column for every possible answer.</p>