Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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'))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading