Good morning!
I have a series of events with associated dates. The event dates are stored as a series of string values in a column within a dataframe that I have loaded into Python. The dataframe contains other columns with values. I would like to convert the values in column "event" into datetime objects, store them in a list, and then plot that list with matplotlib to create a timeseries.
My dataframe looks like this:
date value_1 event other_event
37 07/02/2015 265.09 07/02/2015 NaN
38 08/02/2015 278.59 08/02/2015 NaN
156 06/06/2015 146.07 06/06/2015 NaN
180 30/06/2015 133.56 30/06/2015 NaN
243 01/09/2015 280.27 01/09/2015 01/09/2015
Python tells me that the column data is Name: event, dtype: object, which I assume means it contains string values. I also have the line df.event.apply(str) in my code, which I think will convert the values in my event column into string values.
Then I have this code:
FMT = '%d/%m/%Y'
event_list = []
for i in range(0, len(event)):
event_list.append(datetime.datetime.strptime(event[i], FMT))
However, this line returns an error:
Traceback (most recent call last):
File "<ipython-input-39-e778a465e858>", line 2, in <module>
event_list.append(datetime.datetime.strptime(event[i], FMT))
TypeError: strptime() argument 1 must be string, not float
Any advice as to where I'm going wrong will be gratefully received.