I have a dataframe, like the following, and I intend to fetch windows with size = 30, and then write a loop for each data block and call other functions.
index = pd.date_range(start='2016-01-01', end='2016-04-01', freq='D')
data = pd.DataFrame(np.random.rand(len(index)), index = index, columns=['random'])
I found the following function, but I am wondering if there is a more efficient way to do this.
def split(df, chunkSize = 30):
listOfDf = list()
numberChunks = len(df) // chunkSize + 1
for i in range(numberChunks):
listOfDf.append(df[i*chunkSize:(i+1)*chunkSize])
return listOfDf
source
share