list - Scala代码替换列表形式的数据框中列的空值
问题描述
我正在尝试从列表形式的数据集中替换空值。我使用了下面的代码仍然没有给我想要的结果。我应该怎么办?
我正在使用以下代码:
val mergedDS =customerDS.join(acctstep1,Seq("customerId"),"outer")
.withColumn("numberAccounts", 'numberAccounts.cast("Int"))
.withColumn("totalBalance",'totalBalance.cast("Long"))
// Lets remove all the accounts with missing values for customers
val customerAccountOutputDS = mergedDS.as[CustomerAccountOutput].na.fill(0).show(false)
print(customerAccountOutputDS)
解决方案
import org.apache.spark.sql.functions._
import org.apache.spark.sql.SparkSession;
object DefaultEmptyArray {
def main(args: Array[String]): Unit = {
val input = List(Bean(List("A","B")),Bean(null),Bean(List("C","D")))
val spark = SparkSession.builder().master("local[*]").getOrCreate();
val df = spark.createDataFrame(input)
df.select("inputList")
.withColumn("outputList",when(col("inputList").isNull,Array[String]()).otherwise(col("inputList")))
.show()
}
}
case class Bean( inputList : List[String])
推荐阅读
- dialogflow-es - 在 Web 演示 (DialogFlow) 中添加图像作为响应
- java - 如何从 actionPerformed 返回值到构造函数
- javascript - 添加到数据库 Firebase 后返回值
- mysql - MySQL Rails 在夏令时期间的日期时间值不正确
- rust - 如何为 Rust 对象创建唯一 ID?
- javascript - 删除所有空格
- 标签 ID
- php - Fresh Magento 2.3.0 安装无 CSS
- glpk - GLPK Timeout (tm_lim) 返回找到的最佳解决方案?
- sql - 内连接和左连接查询不支持连接表达式
- r - 查找 R 中每次出现的计数