python - 如何在 python 中加入一个可迭代对象(字符串连接)?
问题描述
我看过其他有类似问题的帖子。
这是我的代码:
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))
推荐阅读
- java - 无法使用 Okhttp 获取响应 cookie
- php - 无法在 Travis-CI 中运行 Laravel 测试
- android - 样式化主题按钮 android (xml)
- php - 如何在 php 中将 mysql 行从在线主机发送到远程 wamp 服务器数据库?
- serverless-framework - 读取 serverless.yml 中的 package.json 名称
- haskell - 关于映射多参数函数的最终结果
- c - 是否可以使用 scanf 验证输入?
- mysql - 找出单调递增的数字范围
- sql-server - 来自 SQL Server 的 PowerShell 查询(计划)并计算记录内的时间
- java - 在 Quarkus 中读取带有属性映射的配置文件