解决如何对sparkStreaming的DataFrame某一column的部分内容进行修改!

所用的软件版本:

spark2.3.0

hbase1.4.6

IDEA2019.1

今天遇到一个问题,sparkStreaming的DataFrame的有些column的内容有换行符\n,然后DF.show()显示时,发现column内容有换行符\n的column,显示有两行。网上查找如何解决的途径,发现filter()方法只是对column名的内容进行过滤选择,对column的内容无法修改,按照https://www.jianshu.com/p/6b8e5963f342https://stackoverflow.com/questions/53016567/scala-dataframe-replace-spaces-with-null-value-using-regexp-replace文章提示,regexp_replace的方法可以进行正则修改regexp_replace(e: Column, pattern: String, replacement: String): Column

首先要导入下面的包:

import org.apache.spark.sql.functions.regexp_replace

然后利用withColum()的方法,能够把column的内容里的换行符\n进行去除

DF.withColumn("列名", regexp_replace(DF("列名"), "\n", ""))

类似的还有一个regexp_extract()方法进行提取!!

 

做好记录,供以后参考!!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值