python - 使用 str 替换为 pandas 系列添加空间
问题描述
我一定是误解了如何使用替换。
输入
box
0 11M000
1 11M000(MU)
期望的输出
box
0 11M000
1 11M000 (MU)
代码
import pandas as pd
data={'box':['11M000','11M000(MU)']}
df = pd.DataFrame(data)
df['box'] = df['box'].str.replace('.(MU)'," (MU)", regex=True)
我现在得到什么
0 11M000
1 11M000 (MU))
解决方案
df['box'] = df['box'].str.replace('('," (")
推荐阅读
- javascript - 从一张桌子获取待处理的好友请求
- caddy - Caddy反向代理,优先文件,然后reverse_proxy
- python - 如何在熊猫中按开始时间和结束时间组合两个数据帧?
- laravel - Laravel POST 路由可以返回一个视图而不是重定向到另一个路由吗?
- amazon-web-services - 在 AWS EC2 实例上托管 Active Directory
- php - 无法通过自定义分类法获取自定义帖子,但如果我使用钩子,我可以。如何获得这些帖子的数组?
- flutter - 在具有多个值的 listView 上进行颤振搜索
- python - Django 与 through 表的多对多关系,如何防止它进行大量查询?
- python - try/except 块的范围
- html - 如何将多个DIV与图片并排设置?