1

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 something like this 44004023323 I have tried this code below but its not working.

df['Lane'] = df['Lane'].apply(lambda x: "0" if x == "-" else x)
Juma Hamdan
  • 69
  • 3
  • 9

2 Answers2

5

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')
  • @JumaHamdan Is the dash always in the middle? This solution will replace all dashes anywhere in the string. – MonkeyZeus Oct 25 '19 at 17:16
2

Try this

df['Lane'] = df['Lane'].apply(lambda x: str(x).replace('-','0'))
Adam Zeldin
  • 898
  • 4
  • 6