python - AttributeError:(“'float'对象没有属性'strip'”,'发生在索引DIV')在熊猫数据框中?
问题描述
我想在我的 pandas 数据框中去除空格。我正在为我的数据框 d1 使用以下代码。
cols = df1.select_dtypes(object).columns df1[cols] = df1[cols].applymap(lambda x: x.strip())
但得到以下错误:
df1[cols] = df1[cols].applymap(lambda x: x.strip()) AttributeError: ("'float' object has no attribute 'strip'", 'occurred at index DIV') 。
如何摆脱这个?
解决方案
推荐阅读
- sonarqube - 项目的格式错误的密钥:name-branch:TASK/X00/XXXX-0000。允许的字符是字母数字、'-'、'_'、'.' 和 ':',至少有一个非数字
- c++ - 在 Redis 缓存中存储 int 类型向量的向量
- python - 如何让我的 discord.py 机器人获取用户的头像?
- python - Python 和 Kotlin 应用程序套接字同步问题
- python - 使用pyodbc将数据从python推送到sql server时使用关键字作为列名的错误
- python - 嗨,我正在用 python 制作一个 2d 光线追踪器,如果对我的阴影系统有任何帮助,我将不胜感激
- visual-studio-code - 表情符号未显示在 VSCode 编辑器中
- angular - 从 Angular 11 更新到 12 时,MatSelect overlayDir 现在是私有的。我现在如何访问它?
- python - 如何使用正确的 sklearn 版本解开和适应机器学习
- c++ - 从暂停到播放时 Gstreamer 管道失败?