python - 由于“不可见”字符,如何将列转换为带有错误的数字
问题描述
我有一个由 pd.read_html 导入的 DF。此列是一个对象。看起来像这样 - 很简单吧?
Column
6 600
7 000
6 700
我要做的是:将其转换为数字我收到一个错误'无法在位置 0 解析字符串“6 600”'这就是为什么我决定删除空格字符''以准备将其转换为数字柱子。
我试过的:
df['Column'] = df['Column'].str.replace(' ','', regex = True)
#==> Nothing changes, it stays like it was. And I still can't move it to numeric.
我也试过:
df['Column'] = df['Column'].map(lambda x:x.split(' ')[0])
#==> The same outcome like above
当我尝试将其转换为数字时,我收到这样的错误:
df['Column'] = df['Column'].astype({'Column': 'int'})
#==> invalid literal for int() with base 10: '6\xa0600'
当我这样做时......
df['Column'] = pd.to_numeric(df['Column'])
#==> Unable to parse string "6 600" at position 0
据我了解,它必须与类型相关联,显然我做错了什么,但我无法理解它是什么。第一个提到的方法(str.replace)中有趣的是我导入的其他数据是可以的。
任何人都可以帮我解决它吗?
解决方案
推荐阅读
- android - Google Nearby Connection:文件交换不会传输整个文件
- unity3d - 不太明白四元数旋转(欧拉角)
- r - 使用 dplyr 在特定列值的第一个实例之后过滤 R 中数据框中的行
- assembly - 我怎样才能画出一个直立的星号三角形?
- c# - 如何检测用户何时从 Visual Studio 运行或何时是常规运行服务
- ubuntu - pandoc:如何设置几何驱动程序
- html - 悬停时如何重置/控制转换延迟?
- java - 如何仅捕获可见通知?安卓
- angular - Angular Reactive Forms Select Option 预选默认值不适用于对象
- jquery - Jquery 按 id 汇总数组