forked from mritzing/fertDataCollector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dateFix.py
25 lines (23 loc) · 6.89 KB
/
dateFix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import re
import random
from pandas import DataFrame
import dateparser
#fix bad date format in fertilizer data
dates = [['Aug 18-22 2014','',''],['Sept 15-19 2014','',''],['Sept 8-12 2014','',''],['Oct 6-10 2014','',''],['Oct 13-17 2014','',''],['Oct 20-24 2014','',''],['Oct 27-31 2014','',''],['Nov 3-7 2014','',''],['Nov 10-14 2014','',''],['Nov 17-21 2014','',''],['Nov 24-28 2014','',''],['Dec 1-5 2014','',''],['Dec 8-12 2014','',''],['Dec 15-19 2014','',''],['Dec 22-26 2014','',''],['Dec 29-Jan 2 2015','',''],['Jan 5-9 2015','',''],['Jan 19-23 2015','',''],['Jan 26-30 2015','',''],['Feb 2-6 2015','',''],['Feb 9-13 2015','',''],['Feb 16-20 2015','',''],['Feb 23-27 2015','',''],['Mar 2-6 2015','',''],['Mar 9-13 2015','',''],['Mar 16-20 2015','',''],['Mar 23-27 2015','',''],['Mar 30-Apr 3 2015','',''],['Apr 6-Apr 10 2015','',''],['Apr 13-17 2015','',''],['Apr 20-24 2015','',''],['Apr 27-May 1 2015','',''],['May 4-8 2015','',''],['May 11-15 2015','',''],['May 18-22 2015','',''],['May 25-29 2015','',''],['June 1-5 2015','',''],['June 8-12 2015','',''],['June 15-19 2015','',''],['June 22-26 2015','',''],['June 29-July 3 2015','',''],['July 6-10 2015','',''],['July 13-17 2015','',''],['July 20-24 2015','',''],['July 27-31 2015','',''],['Aug 3-7 2015','',''],['Aug 10-14 2015','',''],['Aug 17-21 2015','',''],['Aug 24-28 2015','',''],['Aug 31-Sept 4 2015','',''],['Sep 7-11 2015','',''],['Sept 14-18 2015','',''],['Sept 21-25 2015','',''],['Sept 28-Oct 2 2015','',''],['Oct 5-9 2015','',''],['Oct 12-16 2015','',''],['Oct 19-23 2015','',''],['Oct 26-30 2015','',''],['Nov 2-6 2015','',''],['Nov 9-13 2015','',''],['Nov 16-20 2015','',''],['Nov 30-Dec 4 2015','',''],['Dec 7-11 2015','',''],['Dec 14-18 2015','',''],['Dec 21-25 2015','',''],['Dec 29-Jan 2 2015','',''],['Jan 4-8 2016','',''],['Jan 11-15 2016','',''],['Jan 18-22 2016','',''],['Jan 25-29 2016','',''],['Feb 1-5 2016','',''],['Feb 8-12 2016','',''],['Feb 15-19 2016','',''],['Feb 22-26 2016','',''],['Feb 29-Mar 4 2016','',''],['Mar 7-11 2016','',''],['Mar 14-18 2016','',''],['Mar 21-25 2016','',''],['Mar 28-Apr 1 2016','',''],['Apr 4-8 2016','',''],['Apr 11-15 2016','',''],['Apr 18-22 2016','',''],['Apr 25-29 2016','',''],['May 2-6 2016','',''],['May 9-13 2016','',''],['May 16-20 2016','',''],['May 23-27 2016','',''],['May 30-June 3 2016','',''],['June 6-10 2016','',''],['June 13-17 2016','',''],['June 20-24 2016','',''],['June 27-July 1 2016','',''],['July 4-8 2016','',''],['July 11-15 2016','',''],['July 18-22 2016','',''],['July 25-29 2016','',''],['Aug 1-5 2016','',''],['Aug 8-12 2016','',''],['Aug 15-19 2016','',''],['Aug 15-19 2016','',''],['Aug 22-26 2016','',''],['Aug 29-Sept 2 2016','',''],['Sept 5-9 2016','',''],['Sept 12-16 2016','',''],['Sept 19-23 2016','',''],['Sept 26-30 2016','',''],['Oct 10-14 2016','',''],['Oct 17-21 2016','',''],['Oct 24-28 2016','',''],['Oct 31-Nov 4 2016','',''],['Nov 7-11 2016*','',''],['Nov 14-18 2016','',''],['Nov 21-25 2016','',''],['Nov 28-Dec 2 2016','',''],['Dec 5-9 2016','',''],['Dec 12-16 2016','',''],['Dec 19-23 2016','',''],['Dec 26-30 2016','',''],['Jan 2-6 2017','',''],['Jan 9-13 2017','',''],['Jan 16-20 2017','',''],['Jan 23-27 2017','',''],['Jan 30-Feb 3 2017','',''],['Feb 6-10 2017','',''],['Feb 13-17 2017','',''],['Feb 20-24 2017','',''],['Feb 27-Mar 03 2017','',''],['Mar 03-10 2017','',''],['Mar 13-17 2017','',''],['Mar 20-24 2017','',''],['Mar 27-31 2017','',''],['Apr 3-7 2017','',''],['Apr 10-13 2017','',''],['Apr 17-21 2017','',''],['Apr 24-28 2017','',''],['May 8-12 2017','',''],['May 15-19 2017','',''],['May 22-26 2017','',''],['May 29-Jun 02 2017','',''],['June 05-June 09 2017','',''],['June 12-June 16 2017','',''],['June 19-June 23 2017','',''],['June 26-June 30 2017','',''],['July 03-July 07 2017','',''],['July 10-July 14 2017','',''],['July 17-July 21 2017','',''],['July 24-July 28 2017','',''],['July 31-Aug 04 2017','',''],['Aug 07-Aug 11 2017','',''],['Aug 14-Aug 18 2017','',''],['Aug 21-Aug 25 2017','',''],['Aug 28-Sept 01 2017','',''],['Sept 04-Sept 08 2017','',''],['Sept 11-Sept 15 2017','',''],['Sept 18-Sept 22 2017','',''],['Sept 25-Sept 29 2017','',''],['Oct 02-Oct 06 2017','',''],['Oct 09-Oct 13 2017','',''],['Oct 16-Oct 20 2017','',''],['Oct 23-Oct 27 2017','',''],['Oct 30-Nov 03 2017','',''],['Nov 06-Nov 10 2017','',''],['Nov 13-Nov 17 2017','',''],['Nov 20-Nov 24 2017','',''],['Nov 27-Dec 01 2017','',''],['Dec 04-Dec 08 2017','',''],['Dec 11-Dec 15 2017','',''],['Dec 18-Dec 22 2017','',''],['Dec 25-Dec 29 2017','',''],['Jan 01-Jan 05 2018','',''],['Jan 08-Jan 12 2018','',''],['Jan 15-Jan 19 2018','',''],['Jan 22-Jan 26 2018','',''],['Jan 29-Feb 02 2018','',''],['Feb 05-Feb 09 2018','',''],['Feb 12-Feb 16 2018','',''],['Feb 19-Feb 23 2018','',''],['Feb 26-Mar 02 2018','',''],['Mar 05-Mar 09 2018','',''],['Mar 12-Mar 16 2018','',''],['Mar 19-Mar 23 2018','',''],['Mar 26-Mar 30 2018','',''],['Apr 2-Apr 6 2018','',''],['Apr 9-Apr 13 2018','',''],['Aug 14-18 2017','',''],['Sep 11-15 2017','',''],['Oct 9-13 2017','',''],['Nov 6-10 2017','',''],['Dec 4-8 2017','',''],['Jan 1-5 2018','',''],['Jan 29-Feb 2 2018','',''],['Feb 26-Mar 2 2018','',''],['Mar 26-30 2018','',''],['Apr 23-27 2018','',''],['May 21-25 2018','',''],['Jun 18-22 2018','',''],['Jul 16-20 2018','',''],['Aug 13-17 2018','',''],['Aug 7-11 2017','',''],['Sep 4-8 2017','',''],['Oct 2-6 2017','',''],['Oct 27-Nov 3 2017','',''],['Nov 27-Dec 1 2017','',''],['Dec 25-29 2017','',''],['Jan 22-26 2018','',''],['Feb 19-23 2018','',''],['Mar 19-23 2018','',''],['Apr 16-20 2018','',''],['May 14-18 2018','',''],['Jun 11-15 2018','',''],['Jul 9-13 2018','',''],['Aug 6-10 2018','',''],['Jul 31-Aug 4 2017','',''],['Aug 28-Sept 1 2017','',''],['Sep 15-29 2017','',''],['Oct 23-27 2017','',''],['Nov 20-24 2017','',''],['Dec 18-22 2017','',''],['Jan 15-19 2018','',''],['Feb 12-16 2018','',''],['Mar 12-16 2018','',''],['Apr 9-13 2018','',''],['May 7-11 2018','',''],['Jun 4-8 2018','',''],['Jul 2-6 2018','',''],['Jul 30- Aug 3 2018','',''],['Jul 24-28 2017','',''],['Aug 21-25 2017','',''],['Sep 18-22 2017','',''],['Oct 16-20 2017','',''],['Nov 13-17 2017','',''],['Dec 11-15 2017','',''],['Jan 8-12 2018','',''],['Feb 5-9 2018','',''],['Mar 5-9 2018','',''],['Apr 2-6 2018','',''],['Apr 30-May 4 2018','',''],['May 28-June 1 2018','',''],['Jun 25-29 2018','',''],['Jul 23-27 2018','',''],['Jul 17-21 2017','',''],['Jul 10-14 2017','',''],['Jul 3-7 2017','',''],['Jun 26-30 2017','','']]
def fix(dates):
#original string x[0]
#start date x[1]
#end x[2]
for x in dates:
dateStr = x[0]
splitStr = dateStr.split('-')
x[1] = dateparser.parse(splitStr[0] + ' ' + dateStr.split(' ')[-1]).strftime("%m/%d/%Y")
if re.search('[a-zA-Z]', splitStr[1]) is None:
x[2] = dateparser.parse(splitStr[0].split(' ')[0] + ' ' + splitStr[1]).strftime("%m/%d/%Y")
else:
x[2] = dateparser.parse(splitStr[1]).strftime("%m/%d/%Y")
if __name__ == "__main__":
fix(dates)
print(random.sample(dates,5))
df = DataFrame(dates)
df.to_excel('goodDates.xlsx', sheet_name='sheet1', index=False)