I have a pyspark dataframe column with names:
| name |
--------------
|Lebron James|
|Kyrie Irving|
|Kevin Durant|
I want to create a new column such as the following:
| name | trigram |
-----------------------------------------
|Lebron James| Leb ebr bro on Jam ame es
|Kyrie Irving| ...
|Kevin Durant| ...
So far I have
df.withColumn("trigram", regex_replace(col("name"), "([A-Za-z0-9\s]{3})(?!$)", r"$1 "))
But this outputs:
| name | trigram |
--------------------------------------
|Lebron James| Leb ron Ja mes
|Kyrie Irving| Kyr ie Irv ing
|Kevin Durant| Kev in Dur ant
Note: It is important to NOT use udfs. I could simply do what I want with a udf and list comprehension, but I'm looking to do this in the most optimal way since the actual data has hundreds of millions of rows