Original manually manipulated function
df2 = df1.withColumn("test1", col("data.test1"))\
.withColumn("test2", col("data.test2"))\
.withColumn("test3", col("data.test3"))\
.withColumn("test4", col("data.test4"))\
.drop("data")
The state of hope?
for col_name in ['test1', 'test2', 'test3', 'test4']:
df1.withColumn(col_name, col(data.col_name)).drop("data")
Like this... Can I add the .withColumn
function by returning the list of column names I want to manipulate to a repeat statement?
I think I just need to interpolate well.
for col_name in ['test1', 'test2', 'test3', 'test4']:
df1.withColumn(col_name, col("data." + col_name)).drop("data")
© 2024 OneMinuteCode. All rights reserved.