I have this df:
df1 = pd.DataFrame({'Number' : ['one', 'two', '-', '-', 'five'],
'Color' : ['-', 'red', 'blue','yellow', '-']})
---
Number Color
0 one-five -
1 two red
2 - blue-black
3 - yellow
4 five -
I would like to replace with " " (empty space) all cells that contain a specific character ("-" in this case) but only if there is only this char in the cell For exaple:
Number Color
0 one-five
1 two red
2 blue-black
3 yellow
4 five
How can i do this?
CodePudding user response:
try this the replace
function in pandas replace the exact string
matching not like str.replace
df1.replace("-","",inplace=True)