title: Operating on a subset of a DF: impact of different syntax
body: <p>I want to operate on a subset of data in a df using python and pandas. I'm using apply to do the work. Here is the data held in df0:</p>
  
  <pre><code>date         A         B        FX
  1/1/2019   1.7379    1.7379   1.337562
  2/1/2019   1.6604    1.7379   1.336279
  </code></pre>
  
  <p>I'm changing units in the data in column A using column FX, and leaving column B as is.  The first code I use is:</p>
  
  <pre><code>df0.loc[:,'A']=df0.loc[:,'A'].apply(lambda x: x / df0['FX'] * 1.055056)
  </code></pre>
  
  <p>This works fine, producing the data I'm looking for:</p>
  
  <pre><code>date         A         B        FX
  1/1/2019   1.3708    1.7379   1.337562
  2/1/2019   1.3109    1.7379   1.336279
  </code></pre>
  
  <p>The second code piece of code provides the same answers. </p>
  
  <pre><code>df1.loc[:,'A']=df1.apply(lambda x: x / df1['FX'] * 1.055056)
  </code></pre>
  
  <p>Obviously I'm fairly new at this - can someone explain to me in plain english the difference in my two lines of code and why they produce the results they do?</p>
  
  <p>Secondly, if there is a more effective way to operate on a subset of a DF, I would love to hear about that.</p>
  
  <p>Thank you</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Thanks to the comments below. For more color, there is actually hundreds of rows and columns in the dataset, and I choose a subset via a list. The actual code would look more like (based on comments below - thanks all):</p>
  
  <pre><code>df0[list]=df0[list].apply(lambda x: x / df0['FX'] * 1.055056)
  </code></pre>
  
  <p>Or perhaps it is better to avoid lamba and use (I believe this would be correct):</p>
  
  <pre><code>df0[list]=df0[list] / df0['FX'] * 1.055056
  </code></pre>