Reputation: 414
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!
Upvotes: 3
Views: 6828
Reputation: 863531
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]
Upvotes: 4