title: Python 3 Generator Function Returning the Same Value
body: <p>I'm trying to build a batch generator which takes a large Pandas DataFrame as input and output as a given number of rows (batch_size). I practiced on the smaller dataframe with 10 rows to get it work. I have trouble with the generator function where the for loop below works well on the practice dataframe, and spits out the designated batch size:</p>
  
  <pre><code>for i in range(0, len(df), 3):
  lower = i
  upper = i+3
  print(df.iloc[lower:upper])
  </code></pre>
  
  <p>However, trying to build this into a generator function is proving difficult:</p>
  
  <pre><code>def Generator(batch_size, seed = None):
  num_items = len(df)
  x = df.sample(frac = 1, replace = False, random_state = seed)
  for offset in range(0, num_items, batch_size):
      lower_limit = offset
      upper_limit = offset+batch_size
      batch = x.iloc[lower_limit:upper_limit]
      yield batch
  </code></pre>
  
  <p>Unfortunately:</p>
  
  <pre><code>next(Generator(e.g.1))
  </code></pre>
  
  <p>returns the same row over and over again</p>
  
  <p>I'm fairly new to working with this, and I feel I must be missing something, however, I can't spot what.
  If anyone could point out what might be the issue I would very much appreciate it.</p>
  
  <p>Edit:
  The dataframe is predefined, it is:</p>
  
  <pre><code>raw_data = {'first_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy', 'Sarah', 'Gueniva', 'Know', 'Sara', 'Cat'], 
      'last_name': ['Miller', 'Jacobson', 'Ali', 'Milner', 'Cooze', 'Mornig', 'Jaker', 'Alom', 'Ormon', 'Koozer'], 
      'age': [42, 52, 36, 24, 73, 53, 26, 72, 73, 24], 
      'preTestScore': [4, 24, 31, 2, 3, 13, 52, 72, 26, 26],
      'postTestScore': [25, 94, 57, 62, 70, 82, 52, 56, 234, 254]}
  df = pd.DataFrame(raw_data, columns = ['first_name', 'last_name', 'age', 'preTestScore', 'postTestScore'])
  df
  </code></pre>