Pyspark sort by columns or rows

  AI, PySpark, Python

df.orderBy('colname1','colname2',ascending=False)

from pyspark.sql.functions import sort_array
df = spark.createDataFrame([([2, 1, 3],),([1],),([],)], ['data'])
df.show()
+---------+
|     data|
+---------+
|[2, 1, 3]|
|      [1]|
|       []|
+---------+

df0=spark.createDataFrame(df.select(sort_array(df.data).alias('r')).collect(),['data']
df0.show()
+---------+
|     data|
+---------+
|[1, 2, 3]|
|      [1]|
|       []|
+---------+


df1=spark.createDataFrame(df.select(sort_array(df.data, asc=False).alias('r')).collect(),['data'])
df1.show()
+---------+
|     data|
+---------+
|[3, 2, 1]|
|      [1]|
|       []|
+---------+