title: How to pass index to function Python Pandas
body: <p>I am trying to pass an index from a df into my function so that my function can run through all of the rows of the df and provide the output which is a int in a new column called "TDNumber'. </p>
  
  <p>Here is the code</p>
  
  <pre><code> def createTdnumber(onedfindex):
      header.index    
      maski = header.index &lt; onedfindex 
      finder = header[maski]
      tdnumber = max(finder.index)
      return tdnumber
  
  df['TDNumber'] = df.index.apply(createTdnumber())
  </code></pre>
  
  <p>as indicated below The mask should receive a number such as 227
  That 227 would be one of the numbers provided by df.index.apply to the function</p>
  
  <pre><code> def createTdnumber(onedfindex):
      header.index    
      maski = header.index &lt; 227 
      finder = header[maski]
      tdnumber = max(finder.index)
      return tdnumber
  
  df['TDNumber'] = df.index.apply(createTdnumber())
  </code></pre>
  
  <p>This code generates the error 'Int64Index' object has no attribute 'apply'</p>
  
  <p>For the 'Int64Index' how do I pass those numbers one at a time to my function? </p>
  
  <pre><code>header.index 
  </code></pre>
  
  <p>my output is </p>
  
  <pre><code> Int64Index([0, 226, 470, 659, 863, 1108], dtype='int64')
  </code></pre>
  
  <p>from shx2 solution when I run</p>
  
  <pre><code>df.index.to_series()
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>1          1
  2          2
  3          3
  4          4
  5          5
  6          6
  7          7
  8          8
  9          9
  227      227
  228      228
  229      229
  230      230
  471      471
  472      472
  473      473
  474      474
  475      475
  476      476
  </code></pre>