pythondataframegraphlabsframe

Graphlab sframe - Is there a way I can transpose an sframe?


I am using sframes from graphlab library. I need to do a few computations row wise. Also, the sframe structure would make more sense in my case if I was able to transpose the sframe.

Is there a way I can do that? Or is it possible in any other data frame which I could use?

Thanks for your time!


Solution

  • You can try this:

    import graphlab
    import numpy as np
    
    sf = graphlab.SFrame({'id':[1,2,3],'val1':['A','B','C'],'val2':[5,6,7],'val3':['X','Y','Z']})
    print(sf)
    sf_t = np.asarray([sf[x] for x in sf.column_names()])
    print(sf_t)
    

    Here is the result:

    +----+------+------+------+
    | id | val1 | val2 | val3 |
    +----+------+------+------+
    | 1  |  A   |  5   |  X   |
    | 2  |  B   |  6   |  Y   |
    | 3  |  C   |  7   |  Z   |
    +----+------+------+------+
    [3 rows x 4 columns]
    
    [['1' '2' '3']
     ['A' 'B' 'C']
     ['5' '6' '7']
     ['X' 'Y' 'Z']]