新手(spark 数据帧)- df.count().show() 返回 AttributeError

Jay*_*Jay 1 python apache-spark-sql

对于新手问题表示歉意。我刚刚学习。

我只是尝试从 Cloudant 数据库创建 Spark 数据帧并计算条目数。调用函数进行计数后,出现错误:

AttributeErrorTraceback (most recent call last)
<ipython-input-5-56a7e10a510b> in <module>()
----> 1 count(cloudantdata,spark)

<ipython-input-2-f2dcd9d73d7e> in count(df, spark)
      1 def count(df,spark):
      2     #TODO Please enter your code here
----> 3     df.count().show()
      4     return

AttributeError: 'int' object has no attribute 'show'
Run Code Online (Sandbox Code Playgroud)

请参阅笔记本: https://apsportal.ibm.com/analytics/notebooks/c83c959b-2994-4ac7-9af7-f9d33d4dc461/view ?access_token=6a057cadfdd07252e5977a5eb65936185673dd1d1213ab8a003874edbfde6808

use*_*931 5

count()是一个操作(与转换相对),因此它返回一个非 DataFrame 对象 - 在本例中int表示 DataFrame 中的行数。Anint没有调用show()它的方法。

就简单了return df.count()