如何在pyspark中提取和过滤?
数据模式
df = spark.read.parquet(link)
df.printSchema()
# root
# |--user_id : long
# |--date : string
# |--totals: struct
# | |--time: long
# | |--views: long
# | clicks: array
# | |--element: struct
# | | |--clicknumber: long
# | | |--eventinfo : struct
# | | |--eventlabel : string
# | | |--eventaction : string
# | |--item: array
# | | |--element: struct
# | | | | |--itembrand: String
# | | | | |-- itemprice: long
这是我要做的努力的 ,就是创建一个包含date
和eventAction 的pyspark dataframe,而
date
将在2000年3月5日和4/09/2009和品牌
将为“ stihl”。
我之前进行了一些试验,但没有任何结果。
df.select(['date', explode('clicks.eventinfo.eventaction'),
explode('clicks.item')])
df.filter(df.clicks.item.itembrand =='Stihl')
Here's the data schema
df = spark.read.parquet(link)
df.printSchema()
# root
# |--user_id : long
# |--date : string
# |--totals: struct
# | |--time: long
# | |--views: long
# | clicks: array
# | |--element: struct
# | | |--clicknumber: long
# | | |--eventinfo : struct
# | | |--eventlabel : string
# | | |--eventaction : string
# | |--item: array
# | | |--element: struct
# | | | | |--itembrand: String
# | | | | |-- itemprice: long
What I'm struggling to do is creating a PySpark dataframe that contains the date
and the eventaction
while the date
will be between 3/05/2000 and 4/09/2009 and brand
will be "Stihl".
I made some trials before, but without any results.
df.select(['date', explode('clicks.eventinfo.eventaction'),
explode('clicks.item')])
df.filter(df.clicks.item.itembrand =='Stihl')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下。首先,我爆炸了每个数组,然后选择。
Try this. First I exploded every array, then selected.