Python3: поворот 2d-массива панд срез за срезом
I have an (20x4) ndarray and i need to rotate every 4 rows from beginning to form a new ndarray which has size of (5x16). For simplicity, here is a sample of the original data and the intended resulting data with random contents just to infer the way of transpose:
original ndaaray:
0 1 2 3
0 x0 x1 x2 x3
1 x0 x1 x2 x3
2 x0 x1 x2 x3
3 x0 x1 x2 x3
4 z0 z1 z2 z3
5 z0 z1 z2 z3
6 z0 z1 z2 z3
7 z0 z1 z2 z3
8 c0 cm1 c2 c3
9 c0 c1 c2 c3
10 c0 c1 c2 c3
11 c0 c1 c2 c3
12 a0 a1 a2 a3
13 a0 a1 a2 a3
14 a0 a1 a2 a3
15 a0 a1 a2 a3
16 b0 b1 b2 b3
17 b0 b1 b2 b3
18 b0 b1 b2 b3
19 b0 b1 b2 b3
intended ndaaray:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 x0 x0 x0 x0 x1 x1 x1 x1 x2 x2 x2 x2 x3 x3 x3 x3
1 c0 c0 c0 c0 c1 c1 c1 c1 c2 c2 c2 c2 c3 c3 c3 c3
2 a0 a0 a0 a0 a1 a1 a1 a1 a2 a2 a2 a2 a3 a3 a3 a3
3 b0 b0 b0 b0 b1 b1 b1 b1 b2 b2 b2 b2 b3 b3 b3 b3
any suggestions?
What I have tried:
for i in range(0, 20):
df1.loc[i] = df2.loc[0:5, :].transpose().to_numpy()