[Python] Pandas replace from dictionary and regex not working

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am noticing a strance bahavior in the pandas replace function when trying to pass a dictionary with dictionaries as so:

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

    df.replace(mutual_format, regex=True)


    In this case, the col 2 replacement works, however th first one is completly ignored. What am I doing wrong?

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

    Continue reading...

Compartilhe esta Página