gpt4 book ai didi

apache-spark - 如何从Spark Dataframe中的Row对象获取值?

转载 作者:行者123 更新时间:2023-12-03 14:35:37 24 4
gpt4 key购买 nike

对于

averageCount = (wordCountsDF
.groupBy().mean()).head()

我懂了

Row(avg(count)=1.6666666666666667)



但是当我尝试:
averageCount = (wordCountsDF
.groupBy().mean()).head().getFloat(0)

我收到以下错误:

AttributeError: getFloat --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () 1 # TODO: Replace with appropriate code ----> 2 averageCount = (wordCountsDF 3 .groupBy().mean()).head().getFloat(0) 4 5 print averageCount

/databricks/spark/python/pyspark/sql/types.py in getattr(self, item) 1270 raise AttributeError(item) 1271
except ValueError: -> 1272 raise AttributeError(item) 1273 1274 def setattr(self, key, value):

AttributeError: getFloat



我究竟做错了什么?

最佳答案

我想到了。这将为我返回值:

averageCount = (wordCountsDF
.groupBy().mean()).head()[0]

关于apache-spark - 如何从Spark Dataframe中的Row对象获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37999657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com