How to change dataframe column names in pyspark?
Try
df = df.withColumnRenamed("colName", "newColName")\ .withColumnRenamed("colName2", "newColName2")
Use
new_column_name_list= list(map(lambda x: x.replace(" ", "_"), df.columns)) df = df.toDF(*new_column_name_list)
df.withColumnRenamed('age', 'age2')
df = df.select( '*', F.col('count').alias('new_count') ).drop('count')
You need to login first then you can post Your Answer Log in Sign up
Copyright © 2021 Dtuto.Com