【发布时间】:2021-09-14 06:39:05
【问题描述】:
我想基于两列在 PySpark 中执行非典型 regexp_replace:我在一个属性中具有地址,在另一个属性中具有城市,我想使用城市属性从地址中删除它,什么时候展示。我写了一个函数来做到这一点:
df = spark.createDataFrame(
[
(1, 'hügelstrasse 34, ansbach', 'ansbach'),
(2, 'panton st. 2, london', 'london')
],
('id', 'address', 'city')
)
def dropCityAddress(street, city):
new = regexp_replace(street, city, '')
return(new)
df.withColumn('newaddress', dropCityAddress(col('address'), col('city')))
但是 city 对象是不可迭代的。 所需的输出将是地址中没有城市的新列(我对逗号或其他内容不感兴趣,只是删除城市)。我将在大型数据库上执行此任务,因此基于收集操作之类的解决方案不适合此问题。
有没有办法执行这个任务?
【问题讨论】:
-
请为您的问题提供一些示例数据和可重现的场景,您可以按照here 定义的指南了解更多详情
标签: apache-spark pyspark regexp-replace