title: Efficient way to assign values from another column pandas df
body: <p>I'm trying to create a more efficient script that creates a new <code>column</code> based off values in another column. The script below performs this but I can only select one <code>string</code> at a time. I'd like to do this on all individual values.</p>
  
  <p>For the <code>df</code> below I'm currently running the script on each individual <code>string</code> in <code>Location</code>. However, I want to run the script on all <code>unique</code> <code>strings</code>. </p>
  
  <p>Description on how the new column is assigned: Each individual <code>string</code> in <code>Location</code> gets a value for the first 3 unique items in <code>Day</code>. So, for each value in <code>Location</code>, a new string gets assigned to the first 3 unique values in <code>Day</code>. </p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  d = ({
      'Day' : ['Mon','Tues','Wed','Wed','Thurs','Thurs','Fri','Mon','Sat','Fri','Sun'],                 
      'Location' : ['Home','Home','Away','Home','Away','Home','Home','Home','Home','Away','Home'],        
      })
  
  df = pd.DataFrame(data=d)
  
  #Select value
  mask = df['Location'] == 'Home'
  df1 = df[mask].drop_duplicates('Day')
  d = dict(zip(df1['Day'], np.arange(len(df1)) // 3 + 1))
  
  df.loc[mask, 'Assign'] = df.loc[mask, 'Day'].map(d)
  </code></pre>
  
  <p>At the moment I'm selecting each value in <code>['Location']</code>, e.g. <code>mask = df['Location'] == 'Home'</code>. </p>
  
  <p><strong>I want to do it on all values. e.g. <code>mask = df['Location'] == All unique values</code></strong></p>
  
  <p>Intended Output:</p>
  
  <pre><code>      Day Location Assign
  0     Mon     Home     C1
  1    Tues     Home     C1
  2     Wed     Away     C2
  3     Wed     Home     C1
  4   Thurs     Away     C2
  5   Thurs     Home     C3
  6     Fri     Home     C3
  7     Mon     Home     C1
  8     Sat     Home     C3
  9     Fri     Away     C2
  10    Sun     Home     C4
  </code></pre>