Cannot resolve column (numeric column name) in Spark Dataframe

后端 未结 2 1066
离开以前
离开以前 2020-12-29 11:33

This is my data:

scala> data.printSchema
root
 |-- 1.0: string (nullable = true)
 |-- 2.0: string (nullable = true)
 |-- 3.0: string (nullable = true)
         


        
2条回答
  •  春和景丽
    2020-12-29 12:07

    The problem is you can not add dot character in the column name while selecting from dataframe. You can have a look at this question, kind of similar.

    val data = spark.createDataFrame(Seq(
      ("Hello", ", ", "World!")
    )).toDF("1.0", "2.0", "3.0")
    data.select(sanitize("2.0")).show
    
    def sanitize(input: String): String = s"`$input`"
    

提交回复
热议问题