sort values pandas by two columns code example
Example 1: sort by two columns in pandas
df.sort_values(['a', 'b'], ascending=[True, False])
Example 2: pandas sort columns by name
df = df.reindex(sorted(df.columns), axis=1)
Example 3: order dataframe by multiple columns python
df = df.sort_values(["b", "c"], ascending = (False, True))
Example 4: 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()