如何在pyspark中创建动态数据帧名称

2024-09-28 21:36:34 发布

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

如何在pyspark中创建动态数据帧名称 在这里,我无法使用下面的代码创建新的数据帧,它将只给我最后的数据帧名称,我需要所有的数据帧名称

for prime2 in pdf2:
    ol2 =  Bucket_path + prime2['S3_File_with_Path']
    t = 1
    sd = {}  
    testR = "df" + str(t)
    print("testR",testR)
    sd[testR] = spark.read.format("parquet").load(ol2).cache() 
    t = t + 1 


Tags: 数据path代码in名称fors3bucket
1条回答
网友
1楼 · 发布于 2024-09-28 21:36:34

似乎您正在循环中创建dict,因此获取一个只有一个(最后一个)条目的dict。尝试将代码更改为以下内容:

sd = {}  
for prime2 in pdf2:
    ol2 =  Bucket_path + prime2['S3_File_with_Path']
    t = 1
    testR = "df" + str(t)
    print("testR",testR)
    df = spark.read.format("parquet").load(ol2).cache() 
    sd[testR] = df
    t = t + 1 

# sd dict is available here, all the dataframes are inside
print(len(sd))

相关问题 更多 >