3

I have a dataframe, one column of which is filled with entries like this:

2017-03-01T09:30:00.436
2017-03-01T09:30:00.444
...

Is there a way to convert the entire column into datetime format?

So far I have tried using

str.replace('T',' ') over iterrows()

as well as slicing methods but neither seems to work. Any help will be greatly appreciated. Thanks!

1
  • Sure thing @jezrael! Thanks for your help again :) Commented Oct 4, 2017 at 2:44

2 Answers 2

4

Use regex=True for replace substrings:

df['col'] = df['col'].replace('T', ' ', regex=True)

But maybe need only to_datetime:

df = pd.DataFrame({'col':['2017-03-01T09:30:00.436','2017-03-01T09:30:00.444']})

df['col'] = pd.to_datetime(df['col'])
print (df['col'])
0   2017-03-01 09:30:00.436
1   2017-03-01 09:30:00.444
Name: col, dtype: datetime64[ns]
Sign up to request clarification or add additional context in comments.

Comments

0

to_datetime() should work in converting it to datetime format

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.