Home > database >  How to replace a string in DataFrame column (ex : [12-12-12] io [12/12/12])
How to replace a string in DataFrame column (ex : [12-12-12] io [12/12/12])

Time:11-09

I am trying to replace "/" to "-" in the column df['tran_date']:

DataFrame here

I have tried this but it does not work :

df['tran_date'].replace('/','-')

Could you please help? Thank you!

David

CodePudding user response:

replace replaces the whole cell value, to replace a part of the string you need to use str.replace:

df['tran_date'] = df['tran_date'].str.replace('/','-')

CodePudding user response:

Please try this .

df['tran_date'] = df['tran_date'].str.replace('/','-')
  • Related