sort the data by columns in python code example
Example 1: df sort values
>>> df.sort_values(by=['col1'], ascending = False)
col1 col2 col3
0 A 2 0
1 A 1 1
2 B 9 9
5 C 4 3
4 D 7 2
3 NaN 8 4
Example 2: Returns a new DataFrame sorted by the specified column(s)
df.sort(df.age.desc()).collect()
df.sort("age", ascending=False).collect()
df.orderBy(df.age.desc()).collect()
from pyspark.sql.functions import *
df.sort(asc("age")).collect()
df.orderBy(desc("age"), "name").collect()
df.orderBy(["age", "name"], ascending=[0, 1]).collect()