title: Iterate through 3 rows at once in Python 3 using itertools()
body: <p>This piece of code helps to iterate through 2 rows at once.
  How can we iterate through 3 rows at once in a dataframe in pandas?</p>
  
  <p>For example </p>
  
  <p>1,2,3</p>
  
  <p>2,3,4</p>
  
  <p>3,4,5
  etc</p>
  
  <pre><code>from itertools import tee
  from itertools import zip_longest as izip
  def pairwise(iterable):
      "s -&gt; (s0,s1), (s1,s2), (s2, s3), ..."
      a, b = tee(iterable)
      next(b, None)
      return izip(a, b)
  
  for (idx1, row1), (idx2, row2) in pairwise(stock_fut.iterrows()):
      print(idx1,row1,"\n\n",idx2,row2,"\n\n")
  </code></pre>