I want to change names of two columns using spark withColumnRenamed function. Of course, I can write:
data = sqlContext.createDataFrame([(1,2), (3,4)], ['x1', 'x2'])
data = (data
.withColumnRenamed('x1','x3')
.withColumnRenamed('x2', 'x4'))
but I want to do this in one step (having list/tuple of new names). Unfortunately, neither this:
data = data.withColumnRenamed(['x1', 'x2'], ['x3', 'x4'])
nor this:
data = data.withColumnRenamed(('x1', 'x2'), ('x3', 'x4'))
is working. Is it possible to do this that way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…