title: Pandas Series Apply Method
body: <p>I've been using pandas apply method for both series and dataframe, but I am obviously still missing something, because I'm stumped on a simple function i'm trying to execute. </p>
  
  <p>This is what I was doing:</p>
  
  <pre><code>def minmax(row):
      return (row - row.min())/(row.max() - row.min())
  
  row.apply(minmax)
  </code></pre>
  
  <p>but, this returns an all zero Series.  For example, if</p>
  
  <pre><code>row = pd.Series([0, 1, 2])
  </code></pre>
  
  <p>then </p>
  
  <pre><code>minmax(row)
  </code></pre>
  
  <p>returns [0.0, 0.5, 1.0], as desired. But, row.apply(minmax) returns [0,0,0]. </p>
  
  <p>I believe this is because the series is of ints and the integer division returns 0. However, I don't understand, </p>
  
  <ul>
  <li>why it works with minmax(row) (shouldn't it act the same?), and </li>
  <li>how to cast it correctly in the apply function to return appropriate float values (i've tried to cast it using .astype and this gives me all NaNs... which I also don't understand)</li>
  <li>if apply this to a dataframe, as df.apply(minmax) it also works as desired. (edit added)</li>
  </ul>
  
  <p>i suspect i'm missing something fundamental in how the apply works... or being dense. either way, thanks in advance. </p>