我在資料框中有一個分層陣列:
customerId accounts
IND0002 [["IND0002","ACC0155","323"],["IND0002","ACC0262","60"]]
IND0003 [["IND0003","ACC0235","631"],["IND0003","ACC0486","400"],["IND0003","ACC0540","53"]]
IND0004 [["IND0004","ACC0116","965"]]
我需要從陣列 Ex 中的每個串列中提取最后一個元素最低元素:從我應該得到的第一行323,60和第二行應該得到631,400,53
我嘗試使用爆炸功能,但它只提取第一個元素
customerId accounts col
IND0002 [["IND0002","ACC0155","323"],["IND0002","ACC0262","60"]] ["IND0002","ACC0155","323"]
IND0002 [["IND0002","ACC0155","323"],["IND0002","ACC0262","60"]] ["IND0002","ACC0262","60"]
IND0003 [["IND0003","ACC0235","631"],["IND0003","ACC0486","400"],["IND0003","ACC0540","53"]] ["IND0003","ACC0235","631"]
IND0003 [["IND0003","ACC0235","631"],["IND0003","ACC0486","400"],["IND0003","ACC0540","53"]] ["IND0003","ACC0486","400"]
IND0003 [["IND0003","ACC0235","631"],["IND0003","ACC0486","400"],["IND0003","ACC0540","53"]] ["IND0003","ACC0540","53"]
IND0004 [["IND0004","ACC0116","965"]] ["IND0004","ACC0116","965"]
val newDF1 = CustomerAccountOutput.withColumn("accounts", $"accounts"(size($"accounts")).minus(1))
CustomerAccountOutput.select($"customerID",explode($"accounts"))
uj5u.com熱心網友回復:
將
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/389513.html
標籤:数据框 斯卡拉 阿帕奇火花 apache-spark-sql 爆炸
上一篇:如何使用python/pandas中的where條件轉換sql計數?
下一篇:Python:每行平均值的廣告列
