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

0

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')]
Posted by: Guest on April-20-2020

Code answers related to "Returns a new DataFrame sorted by the specified column(s)"

Python Answers by Framework

Browse Popular Code Answers by Language