spark rdd中一列数据由浮点数转换成整数
时间: 2024-02-21 14:11:13 浏览: 93
在 Spark RDD 中使用 map 函数结合 scala.math 库中提供的 round 函数可以将浮点数转换成整数。例如,将 RDD 中的一列浮点数转换成整数:
```scala
val rdd = sc.parallelize(Seq(2.3456, 3.14159, 1.234567))
val intRdd = rdd.map(num => scala.math.round(num).toInt)
```
其中,map 函数将每个浮点数使用 round 函数四舍五入取整,并使用 toInt 函数将结果转换成整数类型。
阅读全文
相关推荐


















