0

I have a table with a timestamp that looks like:2020-03-02T20:33:02

I need to remove everything from T in each row. I tried:

for i in CDCn1["Date"]: 
     CDCn1['Date'] = i.str.replace(r'i[9:]', '')
     print(CDCn1)

and had to do individually:

CDCn2['Date'] = CDCn2['Date'].str.replace(r'T07:13:07', '')

Is there a better way?

wwii
  • 23,232
  • 7
  • 37
  • 77
Daniel
  • 373
  • 1
  • 10
  • 2
    You can use regular expressions: `CDCn2['Date'] = re.sub(r'T.*', '', CDCn2['Date'])`. But your data structure is unclear so it makes it harder to effectively help you. Try to give more details on your data – Tomerikoo Mar 23 '20 at 17:14
  • That works thanks @Tomerikoo – Daniel Mar 23 '20 at 17:25

1 Answers1

0

If the timestamps are all strings you could use

CDCn1['Date']=CDCn1['Date'].str.split('T').str.get(0)

This splits the string on the T and then only keeps the first part.