两个Spark数据帧的并集

2024-10-02 08:26:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在Python中的两个Spark数据帧之间进行联合,其中一个有时是空的,我做了一个测试,如果,返回完整的。 例如下面的一个小代码,它返回一个错误:

>>> from pyspark.sql.types import *
>>> fulldataframe = [StructField("FIELDNAME_1",StringType(), True),StructField("FIELDNAME_2", StringType(), True),StructField("FIELDNAME_3", StringType(), True)]
>>> schema = StructType([])
>>>
>>> dataframeempty = sqlContext.createDataFrame(sc.emptyRDD(), schema)
>>> resultunion = sqlContext.createDataFrame(sc.emptyRDD(), schema)
>>> if (fulldataframe.isEmpty()):
...     resultunion = dataframeempty
... elif (dataframeempty.isEmpty()):
...     resultunion = fulldataframe
... else:
...     resultunion=fulldataframe.union(dataframeempty)
...


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'isEmpty'
>>>

有人能告诉我哪里出了问题?在


Tags: 数据trueschemasparkfieldnamescstructfieldstringtype

热门问题