How Do I Replace All Instances Of A Dash (-) With The Number Zero (0) In The Middle Of A String In Pandas Dataframe?
I have a column that has 5 numbers then a dash then another 5 numbers for example 44004-23323. I would like to remove that dash in the middle. I would like the output to be somethi
Solution 1:
How about .str.replace()?
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html
Pandas: replace substring in string
# see documentation for other parameters, such as regex and case
df['Lane'] = df['Lane'].str.replace('-', '0')
Solution 2:
Try this
df['Lane'] = df['Lane'].apply(lambda x: str(x).replace('-','0'))
Post a Comment for "How Do I Replace All Instances Of A Dash (-) With The Number Zero (0) In The Middle Of A String In Pandas Dataframe?"