Создать функцию в Блокноте данных, чтобы удалить акценты в словах
import unicodedata
import sys
from pyspark.sql.functions import translate, regexp_replace
def make_trans():
matching_string = ""
replace_string = ""
for i in range(ord(" "), sys.maxunicode):
name = unicodedata.name(chr(i), "")
if "WITH" in name:
try:
base = unicodedata.lookup(name.split(" WITH")[0])
matching_string += chr(i)
replace_string += base
except KeyError:
pass
return matching_string, replace_string
def clean_text(c):
matching_string, replace_string = make_trans()
return translate(
regexp_replace(c, "\p{M}", ""),
matching_string, replace_string
).alias(c)
Но я не могу изменить значение в кадре данных, если я выполню команду как select, она работает, но когда я применяю этоКоманда появляется следующая ошибка
Command error: df['productName'] = clean_text(df['productName'])
TypeError: Column is not iterable
Эта команда выполняется с успехом
df.select(clean_text("productName"))
Нужно ли выполнять цикл по одной строке за раз?Это правильный способ работы со спарком + кирпичи данных?