- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 spark 数据框,这里是架构:
|-- eid: long (nullable = true)
|-- age: long (nullable = true)
|-- sex: long (nullable = true)
|-- father: array (nullable = true)
| |-- element: array (containsNull = true)
| | |-- element: long (containsNull = true)
和行样本:。
df.select(df['father']).show()
+--------------------+
| father|
+--------------------+
|[WrappedArray(-17...|
|[WrappedArray(-11...|
|[WrappedArray(13,...|
+--------------------+
类型是
DataFrame[father: array<array<bigint>>]
如何访问内部数组的每个元素?例如第一行的-17?我尝试了不同的东西,比如 df.select(df['father'])(0)(0).show()
但没有成功。
最佳答案
如果我没记错的话,Python 中的语法是
df.select(df['father'])[0][0].show()
或
df.select(df['father']).getItem(0).getItem(0).show()
请在此处查看一些示例:http://spark.apache.org/docs/latest/api/python/pyspark.sql.html?highlight=column#pyspark.sql.Column
关于python - 访问 WrappedArray 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44468311/
我有一个类型为set的列,我使用spark Dataset API的collect_set(),它返回一个包装数组的包装数组。我想要来自嵌套包装数组的所有值的单个数组。我怎样才能做到这一点? 例如。
我的 Dataset 中有一列包含 WrappedArray> .我将此专栏传递给 UDF提取其中一个值。 我将如何访问这个嵌套结构中的 double ? 我想做这样的事情: sparkSession
我在 JAVA 中的 SparkSQL 中解析一个 json 文件,我需要能够访问返回的坐标,这些坐标似乎是 WrappedArrays 的 WrappedArray。这是代码: df.registe
我正在使用 Spark 2.0。我的数据帧有一列,其中包含浮点型 WrappedArrays 的 WrappedArray。 行的示例如下: [[1.0 2.0 2.0][6.0 5.0 2.0][4
我的问题是我必须在一个列表中找到这些不是空的。当我使用过滤器函数不为空时,我也得到每一行。 我的程序代码如下所示: ... val csc = new CassandraSQLContext(s
我有一个 spark 数据框,这里是架构: |-- eid: long (nullable = true) |-- age: long (nullable = true) |-- sex: long
我正在尝试将包含 Array[String] 的列转换为 String,但我始终收到此错误 org.apache.spark.SparkException: Job aborted due to st
我有一段代码如下: List indexes = joinedCols .map(x-> ((Tuple2)x)._1) .collect();
我有一个数据框,如下所示 +---------------------------------------------------------------------+ |value
我对这两个系列有点困惑。 我知道 Scala 的 Array 调用 Java API。在这种情况下,Wrapped Array 的作用是什么(及其性能特征)? http://www.scala-lan
我是Spark和Scala的新手。我正在尝试将函数称为Spark UDF,但遇到了我似乎无法解决的错误。 我了解在Scala中,Array和Seq并不相同。 WrappedArray是Seq的子类型,
两个问题,一般性问题的答案将指导我制作一个 MVCE 的最小限度。 1) 我如何知道预先注册 WrappedArray(以及我可能使用的 Scala 中的所有其他类)?必须使用 Kryo 从库中注册类
scala> def joinWith(separator: String, values: String*): String = { | Array(values).mkStr
我是 Spark/Scala 的初学者。我想在从 Dataset 中选择的 Array 中提取一个值(Double)。简化的主要步骤如下所示。如何提取每个值[Double]最后一个 val wpA ?
我一直在尝试将 RDD 转换为数据帧。为此,需要定义类型而不是 Any。我正在使用 Spark MLLib PrefixSpan,这就是 freqSequence.sequence 的来源。我从一个数
我正在尝试转换 Dataframe 中的 json 文件,但我陷入了基于数组的字段中。我正在使用 Spark 1.6 和 Java。当我读取嵌套的 Json 并转换为 Dataframe 时,我可以读
我有以下架构: geometry: struct (nullable = true) -- coordinates: array (nullable = true) -- el
我有一个有趣的 json 数据,如下所示: [ { "internal_network" : [ { "address" : [ { "address_id" : 2,
我为一个奇怪的运行时错误抓狂: // File: build.sbt scalaVersion := "2.10.1" // File: src/main/scala/bug/Bug.scala pa
Spark 抛ClassCastExpection对 WrappedArray 执行任何操作时 例子: 我有一个像下面这样的 map 输出 输出: Map(1 -> WrappedArray(Pan4
我是一名优秀的程序员,十分优秀!