Applying strptime function to pandas series
Use pd.to_datetime
:
date_series = pd.to_datetime(date_string)
In general it's best have your dates as Pandas' pd.Timestamp
instead of Python's datetime.datetime
if you plan to do your work in Pandas. You may also want to review the Time Series / Date functionality documentation.
As to why your apply
isn't working, args
isn't being read as a tuple, but rather as a string that's being broken up into 17 characters, each being interpreted as a separate argument. To make it be read as a tuple, add a comma: args=('%Y-%m-%d %H:%M:%S',)
.
This is standard behaviour in Python. Consider the following example:
x = ('a')
y = ('a',)
print('x info:', x, type(x))
print('y info:', y, type(y))
x info: a <class 'str'>
y info: ('a',) <class 'tuple'>