0

I would like to remove these brackets and order the dataframe by the R and SP columns. I've tried several things and I get an error. How can I do this?

                 R                  SP
0     [0.6459896423304917]   [0.619298245614035]       M1
1     [0.6494975520851792]  [0.5859649122807016]       M2
2     [0.6560356111719728]  [0.5999999999999998]       M3
3    [0.45921657645058334]  [0.4649122807017543]       M4
4     [0.6302808610901011]  [0.5263157894736838]       M5
..                     ...                   ...       ...
107   [0.5695814044504143]  [0.4771929824561402]       M6
108   [0.6801428488853647]   [0.582456140350877]       M7
  • 3
    Does this answer your question? [Accessing every 1st element of Pandas DataFrame column containing lists](https://stackoverflow.com/questions/37125174/accessing-every-1st-element-of-pandas-dataframe-column-containing-lists) – Chris Jun 08 '20 at 20:06

1 Answers1

0

You can try using applymap with a simple lambda function and then sort the dataframe with sort_values:

test = pd.DataFrame(dict(a=[[3],[1],[2]],b=[[4],[5],[6]])) 

test = test.applymap(lambda x: x[0]) # removing lists
# sorting all the columns
test = pd.DataFrame(np.sort(test.values, axis=0), index=test.index, columns=test.columns) 
#test = test.sort_values(by="a") #sorting based on values in a column