‘DataFrame‘ object has no attribute ‘dtype‘或者‘DataFrame‘ object has no attribute ‘str‘
2020-08-02 18:04
4777 查看
‘DataFrame’ object has no attribute ‘dtype’或者’DataFrame’ object has no attribute ‘str’
使用pandas学习数据分析时报错
原因:使用函数str.strip()去除空格和函数dtype()查看数据类型时,只能一次对一列进行操作。
解决:使用循环语句。
df1 = df.copy() #复制一份文件,防止意外 a1 = list(df.columns) df[a1]= df1[a1].astype(str) #转换为str类型 for i in a1: df[i] = df[i].str.strip() #去除两边空格
相关文章推荐
- python机器学习实战3.2提示错误AttributeError: type object 'str' has no attribute '_name_'
- 'str' object has no attribute 'decode'
- [pygame报错] 运用pygame 进行游戏开发,报错“'str' object has no attribute '_Sprite__g'”,求助
- python3.6报错:AttributeError: 'str' object has no attribute 'decode'
- python3报错:AttributeError:strobjecthasnoattributedecode
- Django: AttributeError: 'str' object has no attribute 'resolve'
- Django2.2.11版本进行数据库迁移发生报错:AttributeError: 'str' object has no attribute 'decode'
- AttributeError: 'str' object has no attribute 'decode'' bytes' object has no attribute 'encode'
- AttributeError: 'str' object has no attribute 'decode'
- celery AttributeError: 'str' object has no attribute 'items'
- Django 错误信息:AttributeError: 'str' object has no attribute '_meta'
- AttributeError: 'DataFrame' object has no attribute 'convert_dtypes'
- python3.7报错:AttributeError: 'str' object has no attribute 'decode'
- Django 错误信息:AttributeError: 'str' object has no attribute '_meta'
- python 中 'str' object has no attribute 'content' 的报错解决
- 用python3连接MySQL数据库出现问题“AttributeError: 'str' object has no attribute 'decode'“解决办法
- Scrapy抓取数据循环报AttributeError: 'str' object has no attribute 'css'
- AttributeError: 'str' object has no attribute 'decode'
- python问题:爬虫出现“AttributeError: 'str' object has no attribute 'sleep'”
- 使用redis和celery执行异步任务时报错AttributeError: 'str' object has no attribute 'iteritems'