I was wondering if there is a way to groupby consecutive index numbers and move the groups in different columns. Here is an example of the DataFrame I'm using:
0
0 19218.965703
1 19247.621650
2 19232.651322
9 19279.216956
10 19330.087371
11 19304.316973
And my idea is to gruoup by sequential index numbers and get something like this:
0 1
0 19218.965703 19279.216956
1 19247.621650 19330.087371
2 19232.651322 19304.316973
Ive been trying to split my data by blocks of 3 and then groupby but I was looking more about something that can be used to group and rearrange sequential index numbers. Thank you!
One way from
pandas
groupby
Here is one way:
Create a new
pandas.Series
with a newpandas.MultiIndex
Similar but with more Numpy
I think that you have assumed that the number of observations within each consecutive group will be the same. My approach is:
Prepare the data:
And the solution:
Which returns:
This is a
groupby
+pivot_table
My way: