У меня есть тренировочный набор данных, где один из столбцов в списке слов.Пример ниже
target id values
0 eng 123 ['hi', 'hello','bye']
1 eng 124 ['my', 'name', 'is']
Теперь у меня есть функция clean (text)
, и я хочу применить ее к столбцу values
.Я попробовал ниже
train = pd.read_json('./file.json')
train['values'] = train['values'].apply(clean)
И получаю ошибку
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Я получаю, что применяю .apply к массиву строк, который не разрешен, но не уверен, как это исправить.
Пожалуйста, предложите
РЕДАКТИРОВАТЬ: Добавление чистой (текст) функции
def clean(text):
import re
from string import punctuation
from nltk.stem import SnowballStemmer
from nltk.corpus import stopwords
def pad_str(s):
return ' '+s+' '
if pd.isnull(text):
return ''
# Empty question
if type(text) != str or text=='':
return ''
# Clean the text
text = re.sub("\'s", " ", text)
text = re.sub(" whats ", " what is ", text, flags=re.IGNORECASE)
#many other regular expression operations
# replace non-ascii word with special word
text = re.sub('[^\x00-\x7F]+', pad_str(SPECIAL_TOKENS['non-ascii']), text)
return text