[Python] Replace column values if it repeats the same character

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

  1. Stack

    Stack Membro Participativo

    I have a dataframe like

    df = pd.DataFrame({'team': ['Red', 'Blue', 'Yellow', 'Green'],
    'points': [11, 7, 8, 10],
    'other': ["kk;aaa;;;", ";;bb;;", ";", ";;;;"]})


    I would like to replace all cells that contain only ";" with "" (empty cells). There may be only 1 or many ";" in a row. If there is anything in the cells other than ";", I would like to leave them as is.

    In my dataframe the other column would become:

    other
    kk;aaa;;;
    ;;bb;;
    #(nothing)
    #(nothing)

    Continue reading...

Compartilhe esta Página