0

I am having issues with Dataframe sort_values() function. If I try to sort it over the 4 column (descending) which contains some positive and some negative numbers it sorts the negatives ok, but the positives are sorted wrong (check the Output). It sorts the negatives separately and positives separately, but are not sorted in uniform fashion. How can I sort the DF from lowest negative to the highest positive number in column 4?

columns = ['1', '2', '3', '4', '5']
rows = ["A", "B"]
cell_text = [['1348','12','177','-0.12','1.7'],
             ['2315','12','174','-0.05','2.1'],
             ['1147','11','137',' 0.02','2.4'],
             ['1375','11','128',' 0.1','3.4']
             ]

df=pd.DataFrame(cell_text,columns=columns)
df=df.sort_values(by=['4'],axis=0,ascending=False)


Output 
      1   2    3      4    5
0  1348  12  177  -0.12  1.7
1  2315  12  174  -0.05  2.1
3  1375  11  128    0.1  3.4
2  1147  11  137   0.02  2.4
Blaz
  • 45
  • 4

0 Answers0