我有一個數據框,如下所示:|------------|-----------|---------------|---------------|| Name | Type | Attribute 1 | Attribute 2 ||------------|-----------|---------------|---------------|| Roger | A | X | Y ||------------|-----------|---------------|---------------|| Roger | A | X | Y ||------------|-----------|---------------|---------------|| Roger | A | X | Y ||------------|-----------|---------------|---------------|| Rafael | A | G | H ||------------|-----------|---------------|---------------|| Rafael | A | G | H ||------------|-----------|---------------|---------------|| Rafael | B | G | H ||------------|-----------|---------------|---------------|我想根據名稱和類型對此數據框進行分區并將其保存到磁盤目前的代碼行看起來像這樣,df.write.partitionBy("Name", "Type").mode("append").csv("output/", header=True)輸出被正確保存,但有重復的行,如下所述在文件夾中/輸出/羅杰/A|---------------|---------------|| Attribute 1 | Attribute 2 ||---------------|---------------|| X | Y ||---------------|---------------|| X | Y ||---------------|---------------|| X | Y ||---------------|---------------|/輸出/拉斐爾/A|---------------|---------------|| Attribute 1 | Attribute 2 ||---------------|---------------|| G | H ||---------------|---------------|| G | H ||---------------|---------------|/輸出/拉斐爾/B|---------------|---------------|| Attribute 1 | Attribute 2 ||---------------|---------------|| G | H ||---------------|---------------| 如您所見,此 csv 包含重復項。使用 write.partitionbY 時如何刪除這些重復項?
如何在 pyspark 數據框中使用 write.partitionBy 時刪除重復項?
慕桂英3389331
2023-10-18 20:39:56