Home > Software engineering >  How would I remove specific characters from only one column in a CSV using python?
How would I remove specific characters from only one column in a CSV using python?

Time:10-14

I need to have my column be only integers, but unfortunately the CSV I need to use has the letters T and Z interspersed.

For example:

2022-09-24T00:30:49Z

How would I go about removing these letters for only this one column? I have tried looking elsewhere, but I can't find anything specifically relating to this.

CodePudding user response:

df["column"]= df["column"].replace(r"T|Z", "", regex = True)

CodePudding user response:

def custom_func(x):
  if isinstance(x,str):
    return x.translate(None,'TZ')
  return x
df.col = df.col.apply(custom_func)

You can use applymap method to apply it to each individual cell if you may

CodePudding user response:

This question should at least get you started in the right direction: Remove cell in a CSV file if a certain value is there

  • Related