You can reorder the columns by using the select() function in PySpark. In the select function, you can pass the column name as a string or multiple columns as a list.
Please find the reference in the pyspark documentation
data = [("Alice", 25, "Engineer"), ("Bob", 30, "Doctor"), ("Charlie", 28, "Teacher")]
columns = ["name", "age", "occupation"]
df = spark.createDataFrame(data, columns)
new_column_order = ["occupation", "name", "age"]
reordered_df = df.select(new_column_order)
reordered_df.show()
# +----------+-------+---+
# |occupation| name|age|
# +----------+-------+---+
# | Engineer| Alice| 25|
# | Doctor| Bob| 30|
# | Teacher|Charlie| 28|
# +----------+-------+---+