0

I have a Pandas dataframe looking like this:

Class Name
2.2 Propellers
4.1 Solenoids
4.10 Barrels
4.7 Collagen
4.9 Beads
5.5 Prisms

and I need to sort it in this format instead:

Class Name
2.2 Propellers
4.1 Solenoids
4.7 Collagen
4.9 Beads
4.10 Barrels
5.5 Prisms

I can do this in python but I was wondering if there is a way that I can do this easily in Pandas. I tried the regular sort but it considers the numbers as floats and therefore doesn't give the desired result.

mb925
  • 137
  • 14
  • If values are floats, why is sorted value `4.10` after `4.9` ? Because in floats `4.1` and `4.10` are same – jezrael Jan 20 '23 at 09:48
  • Or need sorting strings naturally? – jezrael Jan 20 '23 at 09:49
  • Exactly they get sorted like this by Pandas because they are floats. But I want them to be sorted the other way so I actually want "4.10" to be after "4.9" and I don't know how to do it... – mb925 Jan 20 '23 at 09:52
  • It is possible only if use strings, with floats not possible – jezrael Jan 20 '23 at 10:02

0 Answers0