title: Pandas explode a list column, but with extra column, which notes the position in the list
body: <p>Similar to this question: <a href="https://stackoverflow.com/questions/27263805/pandas-column-of-lists-create-a-row-for-each-list-element">Pandas column of lists, create a row for each list element</a></p>
  <p>I want to <code>explode</code> a list column, but also get a rank column. None of the answers given in the above question is really doing the job.</p>
  <p>So, here is how my data frame looks like:</p>
  <pre><code> df =
           a                     b     
  
           1                    [2, 4, 6]
           2                    [1, 5, 8, 10]
  
           ...                   ...
  </code></pre>
  <p><code>b</code> is a list column.</p>
  <p>Here is what I want:</p>
  <pre><code>df = 
         a                       b                 rank 
         1                       2                  1
         1                       4                  2
         1                       6                  3
         2                       1                  1
         2                       5                  2
         2                       8                  3
         2                       10                 4
        ...                      ...                ...
  </code></pre>
  <p>Notice, the <code>rank</code> column. <code>rank</code> says the rank of the respective element in the column <code>b</code>. It could also start with <code>0</code> index. But, it needs to be there.</p>
  <p>Here is what I tried, taking the answer from the question cited:</p>
  <pre><code>      res = df.set_index(['a'])['b'].apply(pd.Series).stack()
  </code></pre>
  <p>Now, the above solution would have worked if <code>b</code> was an equal sized list on all rows. But, it isn't. <code>explode</code> would have worked if I did not need the <code>rank</code> column.</p>
  <p>So, how to do the above?</p>