title: How to write rows to a .csv file using .iloc in pandas python
body: <p>I am searching a .csv file for some numbers using a regular expression. Then when the numbers match, the index of those rows is written to a .csv using .iloc but getting an error. </p>
  
  <pre><code>for each in temp:
  
        if doLuhn(str(each)) is True:
            #print ("In the loop")
            creditcards.append(each)
            Validcardsfound = Validcardsfound + 1
            regex_match_index_list.append(i)
  </code></pre>
  
  <p>then </p>
  
  <pre><code>for each in regex_match_index_list:
  df.iloc[each].to_csv('test.csv')
  </code></pre>
  
  <p>Note : I have create an empty dataframe df.</p>
  
  <p>But I am getting the following error</p>
  
  <blockquote>
    <p>IndexError: single positional indexer is out-of-bounds</p>
  </blockquote>