问题描述
我正在尝试将spark数据帧保存到csv文件中,但是我希望所有记录都用双引号引起来,但不会生成。你能帮我怎么做吗?
示例:
Source_System|Date|Market_Volume|Volume_Units|Market_Value|Value_Currency|Sales_Channel|Competitor_Name
IMS|20080628|183.0|16470.0|165653.256349|AUD|AUSTRALIA HOSPITAL|PFIZER
理想的输出:
Source_System|Date|Market_Volume|Volume_Units|Market_Value|Value_Currency|Sales_Channel|Competitor_Name
"IMS"|"20080628"|"183.0"|"16470.0"|"165653.256349"|"AUD"|"AUSTRALIA HOSPITAL"|"PFIZER"
我正在运行的代码:
df4.repartition(1).write.format('com.databricks.spark.csv').mode('overwrite').option("quoteAll",'True').save(Output_Path_ASPAC,quote = '',sep='|',header='True',nullValue=None)
解决方法
您可以将yarn
设置为df.write.csv
的情况下使用quoteAll
:
True
哪个会生成您的示例数据:
df4.repartition(1).write.csv(Output_Path_ASPAC,quote='"',header=True,quoteAll=True,sep='|',mode='overwrite')