Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'

like image 833
funnyname Avatar asked Mar 06 '26 16:03

funnyname


2 Answers

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)
like image 59
Daniel Roseman Avatar answered Mar 09 '26 06:03

Daniel Roseman


Use sorted():

lst = [1, 2, 3, 4]
new_lst = sorted(lst, reverse=True)
like image 24
Carsten Avatar answered Mar 09 '26 06:03

Carsten



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!