redact_datetime_1.py 614 B

12345678910111213141516
  1. def datestimes(df):
  2. df = df.apply(lambda text: re.sub(r'\d{4}-\d{2}-\d{2}', r'xxx', text)) # 2018-03-15
  3. df = df.apply(lambda text: re.sub(r'[\d ]\d:\d\d \w\w', r'xxx', text)) # 05:30 PM
  4. df = df.apply(lambda text: re.sub(r'\d\d:[0-5]\d:[0-5]\d', r'xxx', text)) # 06:08:18
  5. return df
  6. ############################## Test
  7. ###################################
  8. # text = "I eat potato at 05:30 PM and i'm happy, then i eat again at 10:12 AM, " \
  9. # "2018-03-14 06:08:18, he went on 2018-03-15 06:08:18, lets play, 2018-03-15 slkfldfjezli"
  10. # print(datestimes(pd.Series(text)).values)