replace()函数

1 替换series中的值 

https://jingyan.baidu.com/article/454316ab4d0e64f7a6c03a41.html

2 替换str中的字符

s = 'abcdaaa'
# 注意不会在原数据上直接修改,要重新赋值
s = s.replace('a','A')
print(s)
# 如果s中不存在Y,也不会报错
s = s.replace('Y','A')
print(s)
# 最后一个参数用于规定最多替换几次,2表示最多替换2次
s = s.replace('A','', 2)
print(s)
View Code

ddd

原文地址:https://www.cnblogs.com/xxswkl/p/11563072.html