Answers for "get column of dataframe sorted"

23

sort dataframe by column

df.sort_values(by='col1', ascending=False)
Posted by: Guest on April-30-2020
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 "get column of dataframe sorted"

Python Answers by Framework

Browse Popular Code Answers by Language