scala - 按数组列过滤 Scala 数据帧
问题描述
我的 scala 数据框有一列具有数据类型array
(element: String
)。我想显示该列中包含单词“hello”的数据框的那些行。
我有这个:
display(df.filter($"my_column".contains("hello")))
由于数据不匹配,我收到错误消息。它说argument 1 requires string type, however, '
my:column ' is of array<string> type
。
解决方案
你可以使用array_contains
函数
import org.apache.spark.sql.functions._
df.filter(array_contains(df.col("my_column"), "hello")).show
推荐阅读
- python - Python 类 DRY
- javascript - d3 中的负对数和零对数值
- c - C#error 宏可以显示多行消息吗?
- angular - Angular 中的 Observable 返回 [ Object object ]
- python - 允许使用 Django 和 Meraki Captive Portal API 自动重定向浏览器
- node.js - Node.js 如何同时异步和单线程?
- android - 在播放其他声音时尝试限制其他声音
- chart.js - 如何在 y 轴上突出显示时间序列的最后一个值
- c# - 如何在 c# 中使用 datatable.compute 进行除法?
- html - 如何在 CSS 中结合响应式布局和等高列?