Hướng dẫn dùng pyspark orderby python
You can use either Show
Related: How to sort DataFrame by using Scala Before we start, first let’s create a DataFrame.
This Yields below output.
DataFrame sorting using the sort() functionPySpark DataFrame class provides Syntax
Example
The above two examples return the same below output, the first one takes the DataFrame column name as a string and the next takes columns in Column type. This table sorted by the first
DataFrame sorting using orderBy() functionPySpark DataFrame also provides Example
This returns the same output as the previous section. Sort by Ascending (ASC) If you wanted to specify the ascending order/sort explicitly on DataFrame, you can use the
The above three examples return the same output.
Sort by Descending (DESC)If you wanted to specify the sorting by descending order on DataFrame, you can use the
This yields the below output for all three examples.
Besides Using Raw SQLBelow is an example of how to sort DataFrame using raw SQL syntax.
The above two examples return the same output as above. Dataframe Sorting Complete Example
This complete example is also available at PySpark sorting GitHub project for reference. ConclusionHere
you have learned how to Sort PySpark DataFrame columns using Happy Learning !! |