小编Mah*_*HTB的帖子

列点名称带点火花

我试图从a中取列DataFrame并将其转换为RDD[Vector].

问题是我的名称中有一个带"dot"的列作为以下数据集:

"col0.1","col1.2","col2.3","col3.4"
1,2,3,4
10,12,15,3
1,12,10,5
Run Code Online (Sandbox Code Playgroud)

这就是我正在做的事情:

val df = spark.read.format("csv").options(Map("header" -> "true", "inferSchema" -> "true")).load("C:/Users/mhattabi/Desktop/donnee/test.txt")
val column=df.columns.map(c=>s"`${c}`")
val rows = new VectorAssembler().setInputCols(column).setOutputCol("vs")
  .transform(df)
  .select("vs")
  .rdd
val data =rows.map(_.getAs[org.apache.spark.ml.linalg.Vector](0))
  .map(org.apache.spark.mllib.linalg.Vectors.fromML)

val mat: RowMatrix = new RowMatrix(data)
//// Compute the top 5 singular values and corresponding singular vectors.
val svd: SingularValueDecomposition[RowMatrix, Matrix] = mat.computeSVD(mat.numCols().toInt, computeU = true)
val U: RowMatrix = svd.U  // The U factor is a RowMatrix.
val s: Vector = svd.s  // The singular …
Run Code Online (Sandbox Code Playgroud)

scala apache-spark apache-spark-sql apache-spark-ml apache-spark-mllib

16
推荐指数
2
解决办法
6450
查看次数

计算数据帧Spark中缺失值的数量

我有一个dataset缺少值,我想得到每列的缺失值的数量.以下是我所做的,我得到了非缺失值的数量.如何使用它来获取缺失值的数量?

df.describe().filter($"summary" === "count").show
Run Code Online (Sandbox Code Playgroud)
+-------+---+---+---+
|summary|  x|  y|  z|
+-------+---+---+---+
|  count|  1|  2|  3|
+-------+---+---+---+
Run Code Online (Sandbox Code Playgroud)

请帮助dataframe我们找到一个列,并为每个列找到缺失值的列数.

非常感谢

dataframe apache-spark apache-spark-sql

8
推荐指数
1
解决办法
1万
查看次数

将字符串转换为 BigInt 数据帧 spark scala

我试图将值插入到数据框中,其中字段是string类型到postgresql数据库中,其中字段是大int类型。

我没有找到如何将它们转换为大int。我在使用 IntegerType 之前没有问题。但是使用这个数据框,演员表导致我负整数

val sparkSession = SparkSession.builder.master("local").appName("spark session example").getOrCreate()

  val cabArticleGold = sparkSession.sqlContext.load("jdbc", Map("url" -> "jdbc:oracle:thin:System/maher@//localhost:1521/XE", "dbtable" -> "IPTECH.TMP_ARTCAB")).select("CODEART", "CAB").limit(10)
import sparkSession.sqlContext.implicits._
 cabArticleGold.show()
cabArticleGold.withColumn("CAB",'CAB.cast(IntegerType)).foreach(row=>println(row(1)))

232524399
-1613725482
232524423
-1613725465
232524437
-1191331072
3486
-1639094853
232524461
1564177573
Run Code Online (Sandbox Code Playgroud)

任何使用 Big Int 的帮助将不胜感激。我知道scala支持 Big Int,但我该怎么做?

postgresql dataframe apache-spark apache-spark-sql

3
推荐指数
1
解决办法
1万
查看次数