why do you want to execute it in one line, if you print the execution plan, it actually runs in only one line
data = spark.createDataFrame([(1,2), (3,4)], ['x1', 'x2']) data = (data .withColumnRenamed('x1','x3') .withColumnRenamed('x2', 'x4')) data.explain()
EXIT
== Physical Plan == *(1) Project [x1
if you want to do this with a list tuple, you can use a simple map function
data = spark.createDataFrame([(1,2), (3,4)], ['x1', 'x2']) new_names = [("x1","x3"),("x2","x4")] data = data.select(list( map(lambda old,new:F.col(old).alias(new),*zip(*new_names)) )) data.explain()
still has the same plan
EXIT
== Physical Plan == *(1) Project [x1
source share