I have 1000s of columns in my Spark dataframe. I have a function below to convert the column type one by one. But I want to be able to convert all column types to type double at once. Below code is useful to do for one column at a time.
def convertcolumn(df, name, new_type):
df_1 = df.withColumnRenamed(name, "swap")
return df_1.withColumn(name, df_1["swap"].cast(new_type)).drop("swap")