首页 > 解决方案 > 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') 。

如何摆脱这个?

标签: pythonpython-3.xpandasnumpy

解决方案


推荐阅读