【发布时间】:2019-07-30 12:17:23
【问题描述】:
我需要将 spark 数据帧转换为 CSV 文件。
问题是其中一个特征是向量结构,我不知道如何处理它。由于潜在狄利克雷分配的lda.transform() 函数,我得到了这个数据框。我正在使用spark.ml 库。
我通常使用的通用df.coalesce(1).write.option("header", true).csv("<file output path>") 在这种情况下不起作用。
这是数据框的样子:
org.apache.spark.sql.DataFrame = [label: bigint, topicDistribution: vector]
scala> df_new.show
+-----+--------------------+
|label| topicDistribution|
+-----+--------------------+
| 0|[6.71576085454879...|
| 1|[5.74898984641732...|
| 2|[1.50297841245588...|
| 3|[3.83251655971072...|
| 4|[8.62396858027641...|
| 5|[1.54900186503601...|
| 6|[1.61493761327978...|
| 7|[9.36938609746372...|
| 8|[1.34332824038935...|
| 9|[1.09991943420077...|
| 10|[1.29739085981008...|
| 11|[8.92839698024594...|
| 12|[4.12414455173398...|
| 13|[1.56497583389755...|
| 14|[1.80725990261967...|
| 15|[1.80725990261967...|
| 16|[9.36938609746372...|
| 17|[1.53335069918914...|
| 18|[1.51801264939744...|
| 19|[7.15931646362877...|
+-----+--------------------+
only showing top 20 rows
我不需要将这些数组扩展为单独的功能,只需将其转换为原样即可。 如何将其转换为 CSV 文件?
【问题讨论】:
-
请问为什么
df.coalesce(1).write.option("header", true).csv("<file output path>")不起作用?错误是什么? -
type Vector is not supported...
标签: scala apache-spark