1

I am doing my dataset. I need to sort one of my dataset columns from the smallest to the largest like:

enter image description here

however, when I use :

count20 = count20.sort_values(by = ['Month Year', 'Age'])

I got:

enter image description here

Can anyone help me with this? Thank you very much!

Jean Hu
  • 115
  • 8

1 Answers1

0

define a function like this:

def fn(x):
    output = []
    for item, value in x.iteritems():
        output.append(''.join(e for e in value if e.isalnum()))
    return output

and pass this function as key while sorting values.

count20 = count20.sort_values(by = ['Month Year', 'Age'], key= fn)
mufassir
  • 406
  • 5
  • 16