title: Calculating new column in Pandas dataframe
body: <p>While there are some similar questions, I can't find a straightforward answer to the following. Note that I am coming from R, and quite new to Pandas.</p>
  
  <p>Say I have a Pandas dataframe, df, that contains two columns: "measure" (unicode with 3 levels) and "Airquality" (numpy.float64).</p>
  
  <p>I want to create a third column named "color", that is based on values in "Airquality". Further, I want to do this separately for each level of "measure". I have succeeded by splitting the df on "measure" using df.loc. I then calculated "color" separately in each df using the following code:</p>
  
  <pre><code>#calculate the maximum value of "Airquality" in df for each "measure" level:
  maxi = df['Airquality'].max()
  
  #initialize the column for "color" in df for each "measure" level:
  df['color'] = None
  
  #find the maximum value of "Airquality" in df for each "measure" level:
  maxi = df['Airquality'].max()
  
  #loop through the rows calculating and assigning the value for color,
  #again, in df for each "measure" level
  for i in range(len(df['Airquality'])):
      df['color'][i] = int(100*df['Airquality'][i]/maxi)]
  </code></pre>
  
  <p>However, this runs quite slowly with the large dataset I'm working with, and I'm sure there must be a much better way...probably using some Pandas function and likely without splitting the df into three, one for each "measure" level. Posting this in the hopes of learning from one of the many Python geniuses.</p>