Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

duplicate a column in pyspark data frame [duplicate]

Tags:

People also ask

How do you replicate a column in PySpark?

In order to repeat the column in pyspark we will be using repeat() Function. We look at an example on how to repeat the string of the column in pyspark. Repeat the string of the column in pyspark using repeat() function.

Can spark DataFrame have duplicate columns?

If you perform a join in Spark and don't specify your join correctly you'll end up with duplicate column names.


I have a data frame in pyspark like sample below. I would like to duplicate a column in the data frame and rename to another column name.

Name    Age    Rate
Aira     23     90
Ben      32     98
Cat      27     95

Desired output is :

Name    Age     Rate     Rate2
Aira    23      90       90
Ben     32      98       98
Cat     27      95       95

How can I do it?