pivot table in specific intervals pandas

ojp :

I have a one column dataframe which looks like this:

Neive Bayes
0   8.322087e-07
1   3.213342e-24
2   4.474122e-28
3   2.230054e-16
4   3.957606e-29
5   9.999992e-01
6   3.254807e-13
7   8.836033e-18
8   1.222642e-09
9   6.825381e-03
10  5.275194e-07
11  2.224289e-06
12  2.259303e-09
13  2.014053e-09
14  1.755933e-05
15  1.889681e-04
16  9.929193e-01
17  4.599619e-05
18  6.944654e-01
19  5.377576e-05

I want to pivot it to wide format but with specific intervals. The first 9 rows should make up 9 columns of the first row, and continue this pattern until the final table has 9 columns and has 9 times fewer rows than now. How would I achieve this?

Erfan :

Using pivot_table:

df.pivot_table(columns=df.index % 9, index=df.index // 9, values='Neive Bayes')

              0             1             2             3             4  \
0  8.322087e-07  3.213342e-24  4.474122e-28  2.230054e-16  3.957606e-29   
1  6.825381e-03  5.275194e-07  2.224289e-06  2.259303e-09  2.014053e-09   
2  6.944654e-01  5.377576e-05           NaN           NaN           NaN   

          5             6             7             8  
0  0.999999  3.254807e-13  8.836033e-18  1.222642e-09  
1  0.000018  1.889681e-04  9.929193e-01  4.599619e-05  
2       NaN           NaN           NaN           NaN  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=12636&siteId=1