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

Viewed 44

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

2 Answers

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('/','-')

Please try this .

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