我有一个如下所示的数据帧:
|------------|-----------|---------------|---------------|
| 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)
输出正确保存,但有重复的行,如下所述
文件夹中
/output/Roger/A
|---------------|---------------|
| Attribute 1 | Attribute 2 |
|---------------|---------------|
| X | Y |
|---------------|---------------|
| X | Y |
|---------------|---------------|
| X | Y |
|---------------|---------------|
/output/Rafael/A
|---------------|---------------|
| Attribute 1 | Attribute 2 |
|---------------|---------------|
| G | H |
|---------------|---------------|
| G | H |
|---------------|---------------|
/output/Rafael/B
|---------------|---------------|
| Attribute 1 | Attribute 2 |
|---------------|---------------|
| G | H |
|---------------|---------------|
如您所见,此csv包含重复项。使用write.partitionbY时如何删除这些重复项
在写之前使用
.distinct()
相关问题 更多 >
编程相关推荐