[Python] How to remove non-alpha-numeric characters from strings within a dataframe column?

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have a DF column which has many strings in it. I need to remove all non-alpha numeric characters from that column: i.e:

    df['strings'] = ["a#bc1!","a(b$c"]


    Run code:

    Print(df['strings']): ['abc','abc']


    I've tried:

    df['strings'].replace([',','.','/','"',':',';','!','@','#','$','%',"'","*","(",")","&",],"")


    But this didn't work and I feel that there should be a more efficient way to do this using regex. Any help would be very appreciated.

    Continue reading...

Compartilhe esta Página