Skip to content

Instantly share code, notes, and snippets.

@MaxHalford
Created September 23, 2020 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxHalford/ad2eb310ee8be9da07cb0a4f1fc4440a to your computer and use it in GitHub Desktop.
Save MaxHalford/ad2eb310ee8be9da07cb0a4f1fc4440a to your computer and use it in GitHub Desktop.
Streaming recipes
import pandas as pd
def iter_batches(X_y, batch_size):
x_batch = [None] * batch_size
y_batch = [None] * batch_size
j = 0
for i, (x, y) in enumerate(X_y, start=1):
x_batch[j] = x
y_batch[j] = y
j += 1
if j == batch_size:
index = pd.RangeIndex(i - batch_size, i)
yield (
pd.DataFrame(x_batch, index=index),
pd.Series(y_batch, index=index)
)
j = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment