I want to convert a list of Timex date format strings (from SUTime) into normal datetime format. The problem is, that I have numerous different types:
dates = ['2018-07-09',
'2018-W15',
'2018-02',
'2018-04-06',
'2018-W15',
'2018-02',
'2015-09',
'2018-09-27 INTERSECT P5D',
'FUTURE_REF',
'FUTURE_REF',
'PXY',
'THIS P1D INTERSECT 2018-09-28',
{'end': 'XXXX-06', 'begin': 'XXXX-04'},
'2014-03-19',
'2018-08-02']
I have two objectives:
- Ignore all entries not directly indicating a certain date
- Convert all other to a
'yyyy-mm-dd'format, citing always the first day of the year, month, week, etc. E.g.:'2018-02'should become'2018-02-01'or'2018-W15'2018-04-09
I tried with pandas' pd.to_datetime function, but this does not convert weeks to dates
It's a bit of a challenge when the data collection isn't uniform. I am unfamiliar with Timex and was unable to find any packages that might help.
This might help you out. I wrote some functions that handle each particular case.
OUTPUT: