大 pandas 替换(擦除)字符串中的不同字符 [英] pandas replace (erase) different characters from strings
本文介绍了大 pandas 替换(擦除)字符串中的不同字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一份高中名单.我想从字符串中删除某些字符、单词和符号.
I have a list of high schools. I would like to erase certain characters, words, and symbols from the strings.
我目前拥有:
df['schoolname'] = df['schoolname'].str.replace('high', "")
不过,我想用一个列表来快速替换high
、school
、/
等
However, I would like to use a list so I can quickly replace high
, school
, /
, etc.
有什么建议吗?
df['schoolname'] = df['schoolname'].str.replace(['high', 'school'], "")
不起作用
推荐答案
使用正则表达式(用|
分隔字符串):
Use regex (seperate the strings by |
):
df['schoolname'] = df['schoolname'].str.replace('high|school', "")
这篇关于大 pandas 替换(擦除)字符串中的不同字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文