带点火花的列名 [英] Column name with dot spark
本文介绍了带点火花的列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 DataFrame
中获取列并将其转换为 RDD[Vector]
.
I am trying to take columns from a DataFrame
and convert it to an RDD[Vector]
.
问题是我的名称中有一个点"的列作为以下数据集:
The problem is that I have columns with a "dot" in their name as the following dataset :
"col0.1","col1.2","col2.3","col3.4"
1,2,3,4
10,12,15,3
1,12,10,5
这就是我正在做的:
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 values are stored in a local dense vector.
val V: Matrix = svd.V // The V factor is a local dense matrix.
println(V)
请帮助我考虑名称中带有点的列.谢谢
Please any help to get me consider columns with dot in their names.Thanks
推荐答案
如果你的问题是列名中的.(dot)
,你可以使用`(backticks)
代码> 将列名括起来.
If your problem is the .(dot)
in the column name, you could use `(backticks)
to enclose the column name.
df.select("`col0.1`")
这篇关于带点火花的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文