0
votes

I have a data frame looks like -

id      item      sale
1        a        100
2        b        300
3        c        200
4        d        800
5        e        400

I want data frame sorting in descending order. My final output should -

id      item      sale
4        d        800
5        e        400
2        b        300
3        c        200
1        a        100

My code is -

df = df.orderBy('sale',ascending = False)

But gives me wrong results.

1
Can you check your data type for 'sale'. The code is correct and gives correct result - Neha Jirafe

1 Answers

0
votes

Check the data type of the column sale. It have to be Interger, Decimal or float. You can check the column types with:

df.dtypes

Also, you can try sorting your dataframe with:

df = df.sort(col("sale").desc())