Python中出现‘float‘ object has no attribute ‘strip‘的解决方式

Python中出现‘float‘ object has no attribute ‘strip‘的解决方式,第1张

Python中出现’float’ object has no attribute 'strip’的解决方式

我的原代码是这样的

document = pd.read_csv("sample_data.csv",encoding="utf-8")
#document.columns  = ['sentences'] # 重命名列名
document['公众号文章内容'] = document['公众号文章内容'].apply(lambda x: x.strip()) # 去除文章内容前后的空白
document['文章标题'] = document['文章标题'].apply(lambda x: x.strip()) # 去除文章标题前后的空白
document['lens'] = document['公众号文章内容'].apply(len) # 统计文本长度
document = document[document['lens']>1] # 去除文本长度小于等于1的文本
document.index = np.arange(len(document))

运行后出现了这样的错误:

解决方法:
可以在打开文件的后面加上.astype(str)就可

document = pd.read_csv("sample_data.csv",encoding="utf-8").astype(str)

在运行错误就没有了

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/570580.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存