title: Pandas: Chained assignments
body: <p>I have been reading this <a href="http://pandas-docs.github.io/pandas-docs-travis/indexing.html#indexing-view-versus-copy" rel="noreferrer">link</a> on "Returning a view versus a copy". I do not really get how the <strong>chained assignment</strong> concept in Pandas works and how the usage of <code>.ix()</code>, <code>.iloc()</code>, or <code>.loc()</code> affects it.</p>
  
  <p>I get the <code>SettingWithCopyWarning</code> warnings for the following lines of codes, where <code>data</code> is a Panda dataframe and <code>amount</code> is a column (Series) name in that dataframe:</p>
  
  <pre><code>data['amount'] = data['amount'].astype(float)
  
  data["amount"].fillna(data.groupby("num")["amount"].transform("mean"), inplace=True)
  
  data["amount"].fillna(mean_avg, inplace=True)
  </code></pre>
  
  <p>Looking at this code, is it obvious that I am doing something suboptimal? If so, can you let me know the replacement code lines?</p>
  
  <p>I am aware of the below warning and like to think that the warnings in my case are false positives: </p>
  
  <blockquote>
    <p>The chained assignment warnings / exceptions are aiming to inform the
    user of a possibly invalid assignment. There may be false positives;
    situations where a chained assignment is inadvertantly reported.</p>
  </blockquote>
  
  <p><strong>EDIT :</strong> the code leading to the first copy warning error.</p>
  
  <pre><code>data['amount'] = data.apply(lambda row: function1(row,date,qty), axis=1) 
  data['amount'] = data['amount'].astype(float)
  
  def function1(row,date,qty):
      try:
          if(row['currency'] == 'A'):
              result = row[qty]
          else:
              rate = lookup[lookup['Date']==row[date]][row['currency'] ]
              result = float(rate) * float(row[qty])
          return result
      except ValueError: # generic exception clause
          print "The current row causes an exception:"
  </code></pre>