med*_*v21 3 python string replace dataframe pandas
我有一个地址列,有时它有我要删除的这些字符=> '- "- ,(撇号,双引号,逗号)
我想一次性用空格替换这些字符.我正在使用pandas,这是我到目前为止替换其中一个的代码.
test['Address 1'].map(lambda x: x.replace(',', ''))
Run Code Online (Sandbox Code Playgroud)
有没有办法修改这些代码,以便我可以一次性替换这些字符?对不起是一个菜鸟,但我想了解更多关于熊猫和正则表达的信息.
我们将不胜感激!
你可以使用str.replace:
test['Address 1'] = test['Address 1'].str.replace(r"[\"\',]", '')
Run Code Online (Sandbox Code Playgroud)
样品:
import pandas as pd
test = pd.DataFrame({'Address 1': ["'aaa",'sa,ss"']})
print (test)
Address 1
0 'aaa
1 sa,ss"
test['Address 1'] = test['Address 1'].str.replace(r"[\"\',]", '')
print (test)
Address 1
0 aaa
1 sass
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4965 次 |
| 最近记录: |