-3

Unable to convert every '-' into blank space.

dataset = ['0000sh--_dsd' , '0000sd---_dsd' , '000ad-_512']
test1 = pd.DataFrame(dataset)

I tried this `test1.replace('-',' ',regex=True)

Input: 0000sh--_dsd

I need this as Output: 0000sh _dsd (which is not happening)

Python is not allowing to convert to space. Please advise how to sort out this situation.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • yes looks like this is the solution which you are looking for! [How to replace text in a string column of a Pandas dataframe?](https://stackoverflow.com/questions/28986489/how-to-replace-text-in-a-string-column-of-a-pandas-dataframe) – Usman Arshad Nov 28 '22 at 13:49

1 Answers1

-1

Sorry I realised to late it's a dataframe In this case I would just solve it like this

dataset = ['0000sh--_dsd', '0000sd---_dsd', '000ad-_512']
dataset = [line.replace("-", "") for line in dataset]
test1 = pd.DataFrame(dataset)

Ignore my first answer below


Strings in Python are immutable so you need to use this

test1 = test1.replace('-', '')
ShadowCrafter_01
  • 533
  • 4
  • 19