python - AttributeError:“str”对象在 pandas read_csv 中没有属性“decode”
问题描述
代码
df=pd.read_csv('x.csv', encoding= 'unicode_escape')
utf-8 给出错误
追溯
AttributeError Traceback (most recent call last)
/tmp/ipykernel_9236/1406487559.py in <module>
2 #for review in train['Short_Description']:
3
----> 4 sentences = list(train['Cleaned_Description'].map(lambda x: re.sub("[^a-zA-Z]"," ", (x).decode('utf-8')).lower().split()))
5 test_sentences = [] # Initialize an empty list of sentences
6 #for review in test['Short_Description']:
/opt/conda/lib/python3.7/site-packages/pandas/core/series.py in map(self, arg, na_action)
4159 dtype: object
4160 """
-> 4161 new_values = super()._map_values(arg, na_action=na_action)
4162 return self._constructor(new_values, index=self.index).__finalize__(
4163 self, method="map"
/opt/conda/lib/python3.7/site-packages/pandas/core/base.py in _map_values(self, mapper, na_action)
868
869 # mapper is a function
--> 870 new_values = map_f(values, mapper)
871
872 return new_values
/opt/conda/lib/python3.7/site-packages/pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()
/tmp/ipykernel_9236/1406487559.py in <lambda>(x)
2 #for review in train['Short_Description']:
3
----> 4 sentences = list(train['Cleaned_Description'].map(lambda x: re.sub("[^a-zA-Z]"," ", (x).decode('utf-8')).lower().split()))
5 test_sentences = [] # Initialize an empty list of sentences
6 #for review in test['Short_Description']:
AttributeError: 'str' object has no attribute 'decode'
解决方案
推荐阅读
- javascript - React 上的“TypeError:无法读取未定义的属性‘状态’”
- google-sheets - 倒计时公式不起作用:包括公式中的文本
- css - 反应 onMount 动画
- bash - 远程执行命令 | 仅保留 5 个最近的文件/目录
- html - 如何将 SCSS 添加到 Angular 库的组件中
- c++ - 反向字符串和回文
- django - 表单无效时,FormView get_context_data 不起作用
- c++ - DBus 上的 BlueZ 在不同的时间间隔内停止响应
- python - “解压”一个熊猫系列,复制 DataFrame 的其他值
- postgresql - 在 Postgres 转换中需要帮助