Hi I have an issue automatically rearranging columns in a spark dataframe using Pyspark.
I'm currently summarizing the dataframe according to the aggregation below:
df_agg = df.agg(*[sum(col(c)).alias(c) for c in df.columns])
This results in a summarized table looking something like this (but with hundreds of columns):
| col_1 | col_2 | col_3 | ... | col_N |
|---|---|---|---|---|
| 73 | 55 | 983 | ... | integer |
I would like to automatically rearrange my columns so they are in descending order resulting in a data frame (using the example table above):
| col_3 | col_1 | col_2 | ... | col_N |
|---|---|---|---|---|
| 983 | 73 | 55 | ... | integer (<55) |
Very thankful for all your support!
Best regards