Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 在数据框(Spark)中选择列时,在中间添加一个空列_Scala_Apache Spark_Apache Spark Sql - Fatal编程技术网

Scala 在数据框(Spark)中选择列时,在中间添加一个空列

Scala 在数据框(Spark)中选择列时,在中间添加一个空列,scala,apache-spark,apache-spark-sql,Scala,Apache Spark,Apache Spark Sql,我试图在dataframe select语句的两列之间添加一个空列 使用使用列< /代码>函数,我只能追加作为结束列,但我需要中间的空列(第三列和第六列),如下所示。 val product1 = product.select("_c1","_c2"," ","_c4", "_c5", "_c5", " ", "c6") 我尝试使用栏< >代码< >选择< /Cord>语句,如下所示,给出了错误: val product1 = product.select("_c1","_c2",produ

我试图在dataframe select语句的两列之间添加一个空列

使用<代码>使用列< /代码>函数,我只能追加作为结束列,但我需要中间的空列(第三列和第六列),如下所示。

val product1 = product.select("_c1","_c2"," ","_c4", "_c5", "_c5", " ", "c6")
我尝试使用<代码>栏< <代码> >代码< >选择< /Cord>语句,如下所示,给出了错误:

val product1 = product.select("_c1","_c2",product.withColumn("NewCol",lit(None).cast("string")),"_c4", "_c5", "_c5", " ", "c6")

>error: overloaded method value select with alternatives:
  (col: String,cols: String*)org.apache.spark.sql.DataFrame <and>
  (cols: org.apache.spark.sql.Column*)org.apache.spark.sql.DataFrame
 cannot be applied to (String, String, String, String, String, String, String, String, org.apache.spark.sql.DataFrame, String)
val product1=product.select(“_c1”、“_c2”、product.withColumn(“NewCol”、lit(None)、cast(“string”)、“_c4”、“_c5”、“_c5”、“c6”)
>错误:重载方法值并选择替代项:
(col:String,cols:String*)org.apache.spark.sql.DataFrame
(cols:org.apache.spark.sql.Column*)org.apache.spark.sql.DataFrame
无法应用于(字符串、字符串、字符串、字符串、字符串、字符串、字符串、字符串、org.apache.spark.sql.DataFrame、字符串)

如果有任何建议,请告诉我。感谢您在数据帧中选择列,可以使用字符串(列名)或列(类型)作为输入。从:

然而,这些不能混为一谈。在这种情况下,使用
选择
类型。要获取特定名称的列,请使用
col
函数或
$
(之后)

def select(col: String, cols: String*): DataFrame  
Selects a set of columns.
def select(cols: Column*): DataFrame  
Selects a set of column based expressions.
val spark = SparkSession()....
import spark.implicits._

val product1 = product.select($"_c1", $"_c2", lit(" ").as("newCol1"), $"_c4", $"_c5", $"_c5", lit(" ").as("newCol2"), $"c6")