Code python

Replace Values via regexp_replace Function in PySpark DataFrame

Kontext Kontext visibility 2,498 comment 0 access_time 2 years ago language English

descriptionCode description

PySpark SQL APIs provides regexp_replace built-in function to replace string values that match with the specified regular expression.

It takes three parameters: the input column of the DataFrame, regular expression and the replacement for matches.

pyspark.sql.functions.regexp_replace(str, pattern, replacement)


The following is the output from this code snippet:

|       str_col|int_col|str_col_replaced|
|Hello Kontext!|    100|  Hello kontext!|
|Hello Context!|    100|  Hello kontext!|

All uppercase 'K' or 'C' are replaced with lowercase 'k'.

copyright This page is subject to Site terms.
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts