title: Looping through a second column using a probability input
body: <p>I have a similar question to one I posed here, but subtly different as it includes an extra step to the process involving a probability:</p>
  <p><a href="https://stackoverflow.com/questions/72576406/">Using a Python pandas dataframe column as input to a loop through another column</a></p>
  <p>I've got two pandas dataframes: one has these variables</p>
  <pre><code>Year  Count   Probability
   1      8         25%
   2      26        19%
   3      17        26%
   4      9         10%
  </code></pre>
  <p>Another is a table with these variables:</p>
  <pre><code>ID   Value
  1     100
  2      25
  3      50 
  4      15
  5      75
  </code></pre>
  <p>Essentially I need to use the Count x in the first dataframe to loop through the 2nd dataframe x times, but only pull a value from the 2nd dataframe y percent of the times (using random number generation) - and then create a new column in the first dataframe that represents the sum of the values in the loop.</p>
  <p>So - just to demonstrate - in that first column, we'd loop through the 2nd table 8 times, but only pull a random value from that table 25% of the time - so we might get output of:</p>
  <p>0 100 0 0 25 0 0 0</p>
  <p>...which sums to 125 - so we our added column to the first table looks like</p>
  <pre><code>Year Count  Probability  Sum
   1     8        25%      125
  </code></pre>
  <p>....and so on. Thanks in advance.</p>