【发布时间】:2021-03-18 14:06:15
【问题描述】:
这不是骗子!我已经解决了所有相关问题,但他们没有回答我的问题。
我正在使用标准方法从 pandas 字符串列中去除空格,如 here 所述:
df_obj = df.select_dtypes(['object'])
df[df_obj.columns] = df_obj.apply(lambda x: x.str.strip())
但不断得到:
c:\users\user\appdata\local\programs\python\python37\lib\site-packages\pandas\core\strings.py 如果 inferred_dtype 不在 _validate(data) 中 allowed_types: raise AttributeError("Can only use .str accessor with string values!")
返回 inferred_dtypeAttributeError: 只能使用带有字符串值的 .str 访问器!
当我运行print(df_obj .dtypes) 时,所有列都列为“object”。
那么有什么问题呢?
熊猫版本:'1.1.4'
【问题讨论】: