title: Finding a count column based on 3 different column in pandas
body: <p>I have a pandas data frame in the form of:</p>
  
  <pre><code>user_id referral_code referred_by
  1        A              None
  2        B              A
  3        C              B
  5        None           None
  6        E              B
  7        None           none
  
  ....
  </code></pre>
  
  <p>What I want to do is to create another column weight for each user id such that it will contain the total number of references he has done to others as well as the the number of time he was referred i.e I have to check if the referral_code of a user id is present in the referred_by column and count the frequency of the same and also add 1 if the referred_by column has a entry for the user.</p>
  
  <p>Expected output is:</p>
  
  <pre><code>user_id referral_code referred_by weights
  1        A              None       1
  2        B              A          3
  3        C              B          1
  5        None           None       None
  6        E              B          1
  7        None           none       none
  </code></pre>
  
  <p>The approaches if have tried is using <code>df.grouby</code> along with <code>size</code> and <code>count</code> but nothing is giving the expected output.</p>