根据下面的代码,我正在将数据帧写入csv文件
由于我的数据帧包含None
的""
,我添加了replace("", None)
,因为Null
值应该表示为None
,而不是""
(双引号)
newDf.coalesce(1).replace("", None).replace("'", "\"").write.format('csv').option('nullValue', None).option('header', 'true').option('delimiter', '|').mode('overwrite').save(destination_csv)
我尝试添加.replace("'", "\"").
,但没有效果
该数据还包含带单引号的数据
例如:
Survey No. 123, 'Anjanadhri Godowns', CityName
我需要替换数据帧中的单引号,并将其替换为双引号
如何实现这一目标
在写入输出之前,可以使用
regexp_replace
将所有列中的单引号替换为双引号:使用^{}
这将在
my_col
列中用双引号替换所有出现的单引号字符相关问题 更多 >
编程相关推荐