duplicate a column in pyspark data frame [duplicate]

孤者浪人 提交于 2021-01-18 06:05:42

问题


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?


回答1:


Just

df.withColumn("Rate2", df["Rate"])

or (in SQL)

SELECT *, Rate AS Rate2 FROM df


来源:https://stackoverflow.com/questions/50399361/duplicate-a-column-in-pyspark-data-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!