更新时间:2023-11-13 23:28:40
对于 Spark 1.5 或更高版本,您可以使用 functions 包:
For Spark 1.5 or later, you can use the functions package:
from pyspark.sql.functions import *
newDf = df.withColumn('address', regexp_replace('address', 'lane', 'ln'))
快速说明:
withColumn
以向数据框中添加(或替换,如果名称存在)一列.regexp_replace
将通过替换所有与模式匹配的子字符串来生成一个新列.withColumn
is called to add (or replace, if the name exists) a column to the data frame. regexp_replace
will generate a new column by replacing all substrings that match the pattern.