returns a new dataframe sorted by the specified column 28s 29

Solutions on MaxInterview for returns a new dataframe sorted by the specified column 28s 29 by the best coders in the world

showing results for - "returns a new dataframe sorted by the specified column 28s 29"
Alessandra
03 Nov 2019
1# Returns a new DataFrame sorted by the specified column(s)
2
3df.sort(df.age.desc()).collect()
4# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
5df.sort("age", ascending=False).collect()
6# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
7df.orderBy(df.age.desc()).collect()
8# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
9from pyspark.sql.functions import *
10df.sort(asc("age")).collect()
11# [Row(age=2, name=u'Alice'), Row(age=5, name=u'Bob')]
12df.orderBy(desc("age"), "name").collect()
13# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
14df.orderBy(["age", "name"], ascending=[0, 1]).collect()
15# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]