title: How to refactor `with` statement in Python to use pandas dataframe?
body: <p>I'm trying to refactor the following pseudo-code logic to take the function from reading and writing to files to be all in memory using pandas, but am confused by how the <code>with</code> function operates as compared to a loop over a <code>pandas</code> <code>dataframe</code>.</p>
  
  <p>This is the code I would like to refactor:</p>
  
  <pre><code>results = []
  with open('data.csv', 'rt') as ins:
      next(ins)  # drop header
      a1, b1, c1 = next(ins).strip().split(',')
      for i, line in enumerate(ins, 2):
          a2, b1, c1 = line.strip().split(',')
          ...
          results.append(dummy_func(a1 b1, c1))
      else:
          results.append(dummy_func(a1 b1, c1))
  </code></pre>
  
  <p>Is this the in memory equivalent, in particular I'm not sure if <code>with</code> <code>ins</code> are lines in the file, do I need both <code>itertuples</code>, and on a side note is <code>itertuples</code> the best thing to use here, faster than <code>iterrows</code> for example?</p>
  
  <pre><code>import pandas as pd
  df = pd.read_csv('data.csv', sep=',')
  results = []
  for row in df.itertuples():
      a1, b1, c1 = row.a, row.b, row.c
      for row2 in df.loc[2:].itertuples():
          a1, b1, c1 = row2.a, row2.b, row2.c
          ...
          result.append(dummy_func(a1, b1, c1))
      else: 
          result.append(dummy_func(a1, b1, c1))
  </code></pre>