In case you would like to apply a simple transformation on all column names, this code does the trick: (I am replacing all spaces with underscore)
new_column_name_list= list(map(lambda x: x.replace(" ", "_"), df.columns)) df = df.toDF(*new_column_name_list) Thanks to @user8117731 for toDf trick.