title: How to assign count of unique values to the records in a data frame in python
body: <p>I have a data frame like this:</p>
  
  <pre><code>IP_address
     IP1
     IP1
     IP1
     IP4
     IP4
     IP4
     IP4
     IP4
     IP7
     IP7
     IP7
  </code></pre>
  
  <p>I would like to take count of unique values in this column and add the count as a variable by itself. At the end, it should look like this:</p>
  
  <pre><code>IP_address  IP_address_Count
     IP1               3
     IP1               3
     IP1               3
     IP4               5
     IP4               5
     IP4               5
     IP4               5
     IP4               5
     IP7               3
     IP7               3
     IP7               3
  </code></pre>
  
  <p>I am able to take the unique values of the column using the below code:</p>
  
  <pre><code>unique_ip_address_count = (df_c_train.drop_duplicates().IP_address.value_counts()).to_dict()
  </code></pre>
  
  <p>However, I am not sure how to match these in a loop in python so that i can get the desired results in python. Any sort of help is much appreciated. </p>
  
  <p>I am not able to find a equivalent answer in stackoverflow. If there is anything please direct me there. Thank you. </p>