DataFrame.
sortWithinPartitions
Returns a new DataFrame with each partition sorted by the specified column(s).
DataFrame
New in version 1.6.0.
Changed in version 3.4.0: Supports Spark Connect.
Column
list of Column or column names to sort by.
DataFrame sorted by partitions.
boolean or list of boolean. Sort ascending vs. descending. Specify list for multiple sort orders. If a list is specified, the length of the list must equal the length of the cols.
Examples
>>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"]) >>> df.sortWithinPartitions("age", ascending=False) DataFrame[age: bigint, name: string]