访问WrappedArray元素 [英] Access to WrappedArray elements
本文介绍了访问WrappedArray元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个火花数据框,这是模式:
I have a spark dataframe and here is the schema:
|-- 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()
之类的方法,但是没有运气.
How can I have access to each element of inner array? For example -17 in the first row?
I tried different things like df.select(df['father'])(0)(0).show()
but no luck.
推荐答案
如果我没记错的话,Python中的语法是
If I'm not mistaken, the syntax for in Python is
df.select(df['father'])[0][0].show()
或
df.select(df['father']).getItem(0).getItem(0).show()
See some examples here: http://spark.apache.org/docs/latest/api/python/pyspark.sql.html?highlight=column#pyspark.sql.Column
这篇关于访问WrappedArray元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文