3

At work we recently upgraded to pandas 0.20 and I have a list of numbers that I sort using sort (however this is no longer supported and I am getting the above message when I try sort_values).

numbers = [1, 3, 4, 2] 
numbers.sort(reverse = True) 
print numbers

[4, 3, 2, 1]

numbers.sort_values(reverse = True)

I'm getting this error :

Traceback (most recent call last):

File "", line 1, in

AttributeError: 'list' object has no attribute 'sort_values'

Community
  • 1
  • 1
funnyname
  • 31
  • 1
  • 3

3 Answers3

5

You don't appear to be using pandas at all here; numbers is a standard Python list. And the method to sort a list is just called sort.

numbers.sort(reverse=True)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • cheers, I'm still a novice at this and I used this example without understanding numbers was a standard python list. so I guess if I called the list of number "list" and reran it then I get the same error >>> lst = [1, 3, 4, 2] >>> lst.sort_values(reverse = True) Traceback (most recent call last): File "", line 1, in AttributeError: 'list' object has no attribute 'sort_values' >>> – funnyname Jul 26 '19 at 12:45
4

Use sorted():

lst = [1, 2, 3, 4]
new_lst = sorted(lst, reverse=True)
Carsten
  • 2,765
  • 1
  • 13
  • 28
0

I ended up using sort() rather than sort(reverse = True) and it worked as I wanted, thanks for the help, I really appreciate it.

funnyname
  • 31
  • 1
  • 3