Use the vectorised str
method replace
:
In [30]:
df['range'] = df['range'].str.replace(',','-')
df
Out[30]:
range
0 (2-30)
1 (50-290)
EDIT
So if we look at what you tried and why it didn't work:
df['range'].replace(',','-',inplace=True)
from the docs we see this desc:
str or regex: str: string exactly matching to_replace will be replaced
with value
So because the str values do not match, no replacement occurs, compare with the following:
In [43]:
df = pd.DataFrame({'range':['(2,30)',',']})
df['range'].replace(',','-', inplace=True)
df['range']
Out[43]:
0 (2,30)
1 -
Name: range, dtype: object
here we get an exact match on the second row and the replacement occurs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…