Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between alias and withColumnRenamed

What is the difference between:

my_df = my_df.select(col('age').alias('age2'))

and

my_df = my_df.select(col('age').withColumnRenamed('age', 'age2'))
like image 447
eduardo0 Avatar asked Jul 30 '26 21:07

eduardo0


1 Answers

The second expression is not going to work, you need to call withColumnRenamed() on your dataframe. I assume you mean:

my_df = my_df.withColumnRenamed('age', 'age2')

And to answer your question, there is no difference.

like image 74
Robert Kossendey Avatar answered Aug 02 '26 19:08

Robert Kossendey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!