Data slicing evenly and odd using python

Viewed 45

Say, I have following data in dataframe

      a  
    -1043
    -1107
    -1110
    -1115
    -1193
    -1274
    -133
    -135
    

I want to select data even and odd and basis and put side by side in another variable. I want result something like this

           x          y
        -1043       -1107
        -1110       -1115
        -1193       -1274
        -133        -135

How to do this in a simple way using pandas? Thanks in advance.

1 Answers

Just a reshape:

pd.DataFrame(df['a'].values.reshape(-1,2), columns=['x','y'])

Output:

      x     y
0 -1043 -1107
1 -1110 -1115
2 -1193 -1274
3  -133  -135
Related