如何从pyspark的列中删除连字符?

hwazgwia  于 2021-07-12  发布在  Spark
关注(0)|答案(1)|浏览(338)

我想全部删除 - 从pysparkDataframe列中的元素。
所以我有:

111-345-789   
123654980   
144-900-888  
890890890  
....

我想有一个专栏:

111345789   
123654980   
144900888   
890890890
4ngedf3f

4ngedf3f1#

你可以用 regexp_replace :

df.withColumn("col", F.regexp_replace("col", "-", "")).show()

# +---------+

# |      col|

# +---------+

# |111345789|

# |123654980|

# |144900888|

# |890890890|

# +---------+

或者 replace :

df.withColumn("col", F.expr("replace(col, '-', '')")).show()

相关问题