title: Creating row numbers based on a column value
body: <p>I have the following dataset as input in my jupyter notebook:</p>
  <pre><code>Product   Year    Variable
  A         2018        2
  A         2019        4
  B         2018        2
  B         2019        3
  </code></pre>
  <p>I'm wondering what would be the quickest way to create a loop or something or that sorts in my data set, such that I get the following output:</p>
  <pre><code>Product   Year    Variable   Row_Num
  A         2018        2         1
  A         2018        2         2 
  A         2019        4         1
  A         2019        4         2
  A         2019        4         3
  A         2019        4         4
  B         2018        2         1
  B         2018        2         2
  and so on...
  </code></pre>
  <p>TL;DR - Based on a variable in a particular column, I would like to create rows. Ex- if the variable is 3, I would like to create 3 copies of that row with a column that has values 1,2,3 against it.</p>
  <p>One of the ways I think I found is to first create duplicates based on my variable and then use a function similar to rank() or row_number() to create my &quot;row_num&quot; column. It would be helpful if anyone can share other possible ways to do the same. </p>