【发布时间】:2021-01-27 17:02:58
【问题描述】:
我有一个数据框列表, 在列表的每个位置,我都有一个数据框 我需要将所有这些组合在一个数据框中。 这是在 PySpark 中完成的, 在我使用之前
dataframe_new =pd.concat(listName)
解决方案 1
from pyspark.sql.types import *
import pyspark.sql
from pyspark.sql import SparkSession, Row
customSchema = StructType([
StructField("col1", StringType(), True),
StructField("col2", StringType(), True),
StructField("col3", StringType(), True),
StructField("col4", StringType(), True),
StructField("col5", StringType(), True),
StructField("col6", StringType(), True),
StructField("col7", StringType(), True)
])
df = spark.createDataFrame(queried_dfs[0],schema=customSchema)
我试过的解决方案2:(遍历数据框列表,但不知道如何组合它们
for x in ListOfDataframe
new_df=union_all()
但这总是创建一个 new_df
任何帮助解决这个问题?
【问题讨论】:
-
这能回答你的问题吗? Spark unionAll multiple dataframes
标签: list pyspark apache-spark-sql jupyter-notebook pyspark-dataframes