Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (50.2k points)

I'm trying to sort a dataframe by descending. I put 'False' in the ascending argument, but my order is still ascending.

My code is:

from pandas import DataFrame

import pandas as pd

d = {'one':[2,3,1,4,5],

     'two':[5,4,3,2,1],

     'letter':['a','a','b','b','c']}

df = DataFrame(d)

test = df.sort(['one'], ascending=[False])

but the output is

  letter  one  two

2      b    1    3

0      a    2    5

1      a    3    4

3      b    4    2

4      c    5    1

1 Answer

0 votes
by (108k points)

[False], is a non-empty list, is not the same as False. You have to write:

test = df.sort('one', ascending=False)

Related questions

0 votes
2 answers
asked Jul 22, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
+1 vote
1 answer

Browse Categories

...