使用pyspark的toPandas()错误:'int'对象不可迭代

toPandas() error using pyspark: 'int' object is not iterable

我有一个 pyspark 数据框,我正在尝试使用 toPandas() 将其转换为 pandas,但是我 运行 遇到了下面提到的错误。

我尝试了不同的选项但得到了相同的错误:
1) 将数据限制为只有几条记录
2) 显式使用了 collect()(我相信 toPandas() 固有地使用)

探索了很多关于 SO 的帖子,但是 AFAIK none 有 toPandas() 问题。

我的数据框快照:-

>>sc.version 
2.3.0.2.6.5.0-292

>>print(type(df4),len(df4.columns),df4.count(),
(<class 'pyspark.sql.dataframe.DataFrame'>, 13, 296327)

>>df4.printSchema()
 root
  |-- id: string (nullable = true)
  |-- gender: string (nullable = true)
  |-- race: string (nullable = true)
  |-- age: double (nullable = true)
  |-- status: integer (nullable = true)
  |-- height: decimal(6,2) (nullable = true)
  |-- city: string (nullable = true)
  |-- county: string (nullable = true)
  |-- zipcode: string (nullable = true)
  |-- health: double (nullable = true)
  |-- physical_inactivity: double (nullable = true)
  |-- exercise: double (nullable = true)
  |-- weight: double (nullable = true)

  >>df4.limit(2).show()
+------+------+------+----+-------+-------+---------+-------+-------+------+-------------------+--------+------------+
|id    |gender|race  |age |status |height | city    |county |zipcode|health|physical_inactivity|exercise|weight      |
+------+------+------+----+-------+-------+---------+-------+-------+------+-------------------+--------+------------+
| 90001|  MALE| WHITE|61.0|      0|  70.51|DALEADALE|FIELD  |  29671|  null|               29.0|    49.0|       162.0|
| 90005|  MALE| WHITE|82.0|      0|  71.00|DALEBDALE|FIELD  |  36658|  16.0|               null|    49.0|       195.0|
+------+------+------+----+-------+-------+---------+-------+-------+------+-------------------+--------+------------+
*had to mask few features due to data privacy concerns

错误:-

>>df4.limit(10).toPandas()

'int' object is not iterable
Traceback (most recent call last):
  File "/repo/python2libs/pyspark/sql/dataframe.py", line 1968, in toPandas
pdf = pd.DataFrame.from_records(self.collect(), columns=self.columns)
  File "/repo/python2libs/pyspark/sql/dataframe.py", line 467, in collect
return list(_load_from_socket(sock_info,     BatchedSerializer(PickleSerializer())))
  File "/repo/python2libs/pyspark/rdd.py", line 142, in _load_from_socket
port, auth_secret = sock_info
TypeError: 'int' object is not iterable

我们的自定义库存储库有一个 pyspark 包,它与 spark 集群提供的 pyspark 发生冲突,不知何故两者都适用于 Spark shell 但不适用于笔记本。
因此,重命名自定义存储库中的 pyspark 库解决了问题!