我看过其他有类似问题的帖子。
这是我的代码:
def fit_replace(text):
text = np.array(text)
text = ' '.join(text)
return text
df['REPLACE'] = df['ISI'].apply(fit_replace)
df.head(5)
这是文本中的列表:
[['ini', 'juga', 'saya', 'sambil', 'disambi', 'kerja', 'masih', 'belajar',...
错误:
<ipython-input-101-15e80ecfee7e> in fit_replace(text)
1 def fit_replace(text):
2 text = np.array(text)
----> 3 text = ' '.join(text)
4 return text
5
TypeError: can only join an iterable
首先需要将text
转换为可迭代的。
例如:
' '.join(list(text))
您应该使用:
df['REPLACE'] = df['ISI'].apply(''.join)
将为您省去定义单独功能、转换广告应用程序的麻烦。