I have data in a Dataframe structured like so...
D K Factor p
0 -0.483128 -1.240024 -1.214765 -1.002418
1 -0.692334 -1.632132 1.562630 0.997304
2 -1.189383 -1.632132 1.562630 0.997304
3 -1.691841 -1.632132 1.562630 0.997304
4 -2.084926 -1.632132 1.562630 0.997304
I'm trying to reorganize the data into a new structure where each row contains 'period' number of rows from the existing data. Moves ahead one row in existing and the stacks the next 'period lines'.
the function so far:
def prepData(seq, period):
newStacks = pd.DataFrame()
for pos in range(0, len(seq) - (period+1), 1):
chunk = (seq[pos:pos + period])
stack = []
for sliver in range(0, len(chunk), 1):
piece = (chunk.iloc[sliver:])
print(piece)
stack.append(piece)
newStacks.append(chunk)
return newStacks
this obviously is not efficient and aside doesn't produce the desire structure. The aim is to get a structure like below considering period = 3
0 -0.483128 -1.240024 -1.214765 -1.002418 -0.692334 -1.632132 1.562630 0.997304 -1.189383 -1.632132 1.562630 0.997304
1 -0.692334 -1.632132 1.562630 0.997304 -1.189383 -1.632132 1.562630 0.997304 -1.691841 -1.632132 1.562630 0.997304
2 -1.189383 -1.632132 1.562630 0.997304 -1.691841 -1.632132 1.562630 0.997304 -2.084926 -1.632132 1.562630 0.997304
AA Simple way to accomplish this would be appreciated.