title: Python: Subtract Previous Row Index from Current Row, Same Index [Without Pandas]
body: <p>I am a Python (and programming as a whole) novice. I have seen hundreds of questions about this but all use the <code>pandas</code> package for data analysis. I already have several hundred lines of code which have not used <code>pandas</code> so I want to avoid <code>pandas</code> if possible, or if I can restructure my data using <code>pandas</code>, I am open for suggestions. </p>
  
  <p>I have several thousand lines of raw data made into lists as <code>entries</code>. I use <code>column</code> to create another list from <code>entries</code> for simplicity of executing my functions.</p>
  
  <p>I want to subtract an index (<code>entries[2]</code>) of a previous row from the same index of the current row. I see two ways of completing this: </p>
  
  <p>current line <code>entries[2]</code> - previous line <code>entries[2]</code></p>
  
  <p>or </p>
  
  <p>current line <code>Elapsed Time</code> - previous line <code>Elapsed Time</code></p>
  
  <p>Sample Raw Data:</p>
  
  <pre><code>1 c    4977321 200 200 007 003 033 001 002 003 092 001 
  2 d    4977789 010 120 100 100 
  3 e    4977816 175 194 000 
  4 f    4977868 225 220 100 300 001
  </code></pre>
  
  <p>Here, index 2 is time (i.e. 4977321) </p>
  
  <p>My Code looks like this:</p>
  
  <pre><code>f = input('Type in File Name: ')  # What Raw Data log do we want to analyze?
  
  
  def function():
      print_string = ''
      # do something with the data
      print_string += 'Time Delta: ' + str(delta_time)
      if 'Time Delta' in print_string:
          print(print_string)
  
  
  initial_time = None  # Establishes 0 start point for time (not all captures start at 0ms)
  with open(f, "r") as f:
      for line in f:
          entries = line.split()  # Organizes data line as a list, entries as indices
          column = [int(v) for v in entries[3:]]  
          delta_time = int(entries[2]) - time
          time = int(entries[2])  # Time expressed in milliseconds
          if initial_time is None:
              initial_time = time
              delta_time = 0
          elap_time = time - initial_time  # Expressed as elapsed time from start of capture in milliseconds
          function()
  
  f.close()
  </code></pre>
  
  <p>I have left out the bulk of the body of my code (entirely functions) as I did not see it a necessary piece of information. </p>
  
  <p>I want the code to determine a value for <code>delta_time</code> and so it can print after executing the function. I would like the output to look like:</p>
  
  <pre><code>Time Delta: #  (nothing here, no previous line)
  Time Delta: #  4977789 - 4977321
  Time Delta: #  4977816 - 4977789 
  Time Delta: #  4977868 - 4977816 
  </code></pre>
  
  <p>FYI, I used <code>elap_time</code> in my function when printing as well, just did not include it here.</p>