我正在研究Spark mllib算法。我拥有的数据集是这种形式
公司”:“XXXX”,“CurrentTitle”:“XYZ”,“Edu_Title”:“ABC”,“Exp_mnth”:。(还有更多与之相似的值)
我试图将字符串值原始编码为数字值。因此,我尝试使用zipwithuniqueID作为每个字符串值的唯一值。由于某种原因,我无法将修改后的数据集保存到磁盘上。我可以使用spark SQL以任何方式执行此操作吗?或哪种更好的方法呢?
最佳答案
Scala
val dataFrame1 = dataFrame0.withColumn("index",monotonically_increasing_id())
Java
Import org.apache.spark.sql.functions;
Dataset<Row> dataFrame1 = dataFrame0.withColumn("index",functions.monotonically_increasing_id());
关于apache-spark - 如何在Spark SQL中为表添加增量列ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38377101/