Replace 如何用特定字符串替换列的内容?
大家好 因此,我有这个表(它只是原始数据集的一个子集): 我想用IT-Rome-兴业银行 因此,我的输出应该如下所示:Replace 如何用特定字符串替换列的内容?,replace,pyspark,Replace,Pyspark,大家好 因此,我有这个表(它只是原始数据集的一个子集): 我想用IT-Rome-兴业银行 因此,我的输出应该如下所示: 如果您能为我们提供帮助,我们将不胜感激,谢谢您我不明白您的要求。。 你在找这个简单的更新语句吗? 假设您的表名为表1 UPDATE Table_1 SET Customer = 'IT-Rome - societe generale' WHERE Customer like ('IT - ROME%') GO 在Pyspark中使用类似的操作符: from pyspa
如果您能为我们提供帮助,我们将不胜感激,谢谢您我不明白您的要求。。 你在找这个简单的更新语句吗? 假设您的表名为表1
UPDATE Table_1
SET Customer = 'IT-Rome - societe generale'
WHERE Customer like ('IT - ROME%')
GO
在Pyspark中使用类似的
操作符:
from pyspark.sql import functions as F
from pyspark.sql.functions import col
df.withColumn("Customer", F.when(col('Customer').like('IT - Rome%')\
, 'IT - Rome - societe generale').otherwise(col('Customer'))).show()
+----------------------------+-------+
|Customer |Country|
+----------------------------+-------+
|IT - Rome - societe generale|Italy |
|DE - Berlin - BNP ParisBas |Germany|
|IT - Rome - societe generale|Italy |
|FR - Paris - CreditAgricole |France |
+----------------------------+-------+
我想用IT-ROME-societe generale替换Customer列中以IT-ROME开头的所有字符串?
UPDATE Table_1
SET Customer = 'IT-Rome - societe generale'
WHERE Customer like ('IT - ROME%')
GO
from pyspark.sql import functions as F
from pyspark.sql.functions import col
df.withColumn("Customer", F.when(col('Customer').like('IT - Rome%')\
, 'IT - Rome - societe generale').otherwise(col('Customer'))).show()
+----------------------------+-------+
|Customer |Country|
+----------------------------+-------+
|IT - Rome - societe generale|Italy |
|DE - Berlin - BNP ParisBas |Germany|
|IT - Rome - societe generale|Italy |
|FR - Paris - CreditAgricole |France |
+----------------------------+-------+