[Python] Why isn't this removing non-alphanumerical characters?

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

  1. Stack

    Stack Membro Participativo

    import pandas as pd


    df = pd.read_csv('911.csv')


    df['desc'].str.replace('[^a-zA-Z0-9]','').head()


    0 REINDEER CT & DEAD END; NEW HANOVER; Station ...
    1 BRIAR PATH & WHITEMARSH LN; HATFIELD TOWNSHIP...
    2 HAWS AVE; NORRISTOWN; 2015-12-10 @ 14:39:21-St...
    3 AIRY ST & SWEDE ST; NORRISTOWN; Station 308A;...
    4 CHERRYWOOD CT & DEAD END; LOWER POTTSGROVE; S...
    Name: desc, dtype: object


    I'm trying to remove all non-alphanumerical characters in the desc column. I tried the same code with other columns but it doesn't seem to be working.

    Continue reading...

Compartilhe esta Página