def random_sample(data=None, timesteps=100, batch_size=100, subset='train'):
    if subset == 'train':
        offset = 0
rand_stocks = np.random.randint(0, len(data), size=batch_size)
ret_data = []
for idx in rand_stocks:
    stock = data[idx]
start_idx = np.random.randint(offset, len(stock) - timesteps)
d = stock[start_idx:start_idx + timesteps]
ret_data.append(d)
return ret_data
Python Pandas -- Random sampling of time series