python-3.x - 将列(1234)中带有空格的数字字符串转换为int
问题描述
我尝试将数字字符串转换1 111
为数据框列中的 int: df_ga['Count'] = [float(str(val).replace(' ','').replace(',','.' )) 对于 df_ga['Count'].values 中的 val
但它返回:
ValueError: could not convert string to float: '1\u202f111'
我也试过替换和正则表达式
df_ga['Count'] = df_ga['Count'].replace(' ', '')
和
df_ga.Count = df_ga.Count.replace('\s+', ' ', regex=True)
他们回来了:
ValueError: Unable to parse string "1 111" at position 134
我试过 coerce pero me da NaN
解决方案
推荐阅读
- android - Facebook 深度链接在 Android 上的错误行为
- java - 无法让android创建通知
- google-cloud-data-fusion - 创建系统计算配置文件
- rest - 下游验证失败时的 Http 状态码
- angular - 如何让不同的 MAT-TAB 共享相同的 HTML 代码
- spring - Hibernate 连接表在列问题上是唯一的
- python - 如何更新纯函数?
- java - Spring Boot,如何在具有 EmbeddedId 的表中插入新记录
- amazon-web-services - 从第三方获取数据到 EC2 是否被视为入站数据?
- postgresql - Postgres 不接受端口 5432 上的 TCP/IP