从字典和正则表达式替换不起作用

2024-09-29 19:32:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我注意到pandas replace函数中有一个strance bahavior,它试图用字典传递字典,如下所示:

mutual_format = {'col1' : {'(?i)o':'0', '[^\d)]':''},
                  'col2' : {'name ':''}}

df.replace(mutual_format, regex=True)

在这种情况下,列2替换工作,但第一个被完全忽略。 我做错什么了?你知道吗

col1             |   col2
0004564321 / O       name asdfg asd as
00045632145 / O      name bla bla
00045632145           name asdf asdf 

Tags: 函数nameformatpandasdf字典replacecol2

热门问题