mardi 4 août 2015

pandas - splitting columns

I have some data imported from a csv, to create something similar I used this:

data = pd.DataFrame([[1,0,2,3,4,5],[0,1,2,3,4,5],[1,1,2,3,4,5],[0,0,2,3,4,5]], columns=['split','sex', 'group0Low', 'group0High', 'group1Low', 'group1High'])
means = data.groupby(['split','sex']).mean()

so the dataframe looks something like this:

enter image description here

        group0Low   group0High  group1Low   group1High
split   sex             
0   0   123 54  95  265
    1   98  111 120 220
1   0   211 300 150 190
    1   132 250 139 86

You'll notice that each column actually contains 2 variables (group# and height). It was set up this way for running repeated measures anova in SPSS, but that's beyond the point.

Ideally, I want to use pandas to split the columns up, so I can also groupby "group", like this (I actually screwed up the order of the numbers, but hopefully the idea is clear):

enter image description here

            low high
split   sex group       
    0   0   95  265
0   0   1   123 54
    1   0   120 220
    1   1   98  111
1   0   0   150 190
    0   1   211 300
    1   0   139 86
    1   1   132 250

is how do I achieve this in pandas? Is it even possible?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire