user678 9
0
Q:

Returns a new DataFrame sorted by the specified column(s)

# Returns a new DataFrame sorted by the specified column(s)

df.sort(df.age.desc()).collect()
# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
df.sort("age", ascending=False).collect()
# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
df.orderBy(df.age.desc()).collect()
# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
from pyspark.sql.functions import *
df.sort(asc("age")).collect()
# [Row(age=2, name=u'Alice'), Row(age=5, name=u'Bob')]
df.orderBy(desc("age"), "name").collect()
# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
df.orderBy(["age", "name"], ascending=[0, 1]).collect()
# [Row(age=5, name=u'Bob'), Row(age=2, name=u'Alice')]
0

New to Communities?

Join the community