Home > Software engineering >  Replace column values if it repeats the same character
Replace column values if it repeats the same character

Time:10-04

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)

CodePudding user response:

You can use res

  • Related