Renaming column names of a DataFrame in Spark Scala

后端 未结 6 1635
攒了一身酷
攒了一身酷 2020-11-28 02:04

I am trying to convert all the headers / column names of a DataFrame in Spark-Scala. as of now I come up with following code which only replaces a single colum

6条回答
  •  孤街浪徒
    2020-11-28 02:17

    For those of you interested in PySpark version (actually it's same in Scala - see comment below) :

        merchants_df_renamed = merchants_df.toDF(
            'merchant_id', 'category', 'subcategory', 'merchant')
    
        merchants_df_renamed.printSchema()
    

    Result:

    root
    |-- merchant_id: integer (nullable = true)
    |-- category: string (nullable = true)
    |-- subcategory: string (nullable = true)
    |-- merchant: string (nullable = true)

提交回复
热议问题