The .orderBy(...) transformation sorts the results given the columns specified. An equivalent from the SQL world would also be ORDER BY.
Look at the following code snippet:
# sort by width (W)
sample_data_schema.orderBy('W').show()
It produces the following output:
The SQL equivalent would be:
SELECT *
FROM sample_data_schema
ORDER BY W
You can also change the order of sorting to descending by using the .desc() switch of a column (the .col(...) method). Look at the following snippet:
# sort by height (H) in descending order
sample_data_schema.orderBy(f.col('H').desc()).show()
It produces the following output:
Put in SQL syntax, the preceding expression would be:
SELECT *
FROM sample_data_schema
ORDER BY H DESC