Home > Enterprise >  Why the .replace function is not working?
Why the .replace function is not working?

Time:02-18

im trying to erase "." from a DataFrame column using the replace function but i have no idea why is not working. The currently column looks like:

Time
5:00 PM
4:00AM
3:30 P.M
2:00 .P.M

What i want is to change that column to a DataTime Hour type , but i think that i need to clean it first. So, in order to do that i want to erase the "." but when i use:

df.Time=df.Time.replace({'.':''})

still does not work. How can i do it?

CodePudding user response:

You can use

print(df.Time.str.replace('.','', regex=True))

CodePudding user response:

You can use:

df.Time=df.Time.apply(lambda x: x.replace('.',''))
  • Related