Sep-06-2017, 03:14 PM
This is the code that cleans up the data.
It captures the column header 'created' a long with the date values
The column header 'created' prevents me from converting the dates into datetime objects because it is not in the correct format.
I'm trying to separate it out with a simple if else statement but it does not seem to recognize it and it always goes into the else block.
I have tried passing the value with and without striping the it, values.strip()
I've added '/n' to the compare values=='created/n'
I've added spaces, ' created ' to the compare statement.
It captures the column header 'created' a long with the date values
The column header 'created' prevents me from converting the dates into datetime objects because it is not in the correct format.
I'm trying to separate it out with a simple if else statement but it does not seem to recognize it and it always goes into the else block.
I have tried passing the value with and without striping the it, values.strip()
I've added '/n' to the compare values=='created/n'
I've added spaces, ' created ' to the compare statement.
#############################this function is used to clean specific fields - not the overall document###################### def cleanTheData(ds): # removes excess characters from sys_created_on values cleanedData = list() # clears list for values in ds['sys_created_on']: values.strip() print('Before the if else block', values) if values=='created': cleanedData.append(re.sub(',+|\\r|\\n|', ' ', values)) print('in the if statement', values) else: print('in the else statement', values) #cleanedData.append(datetime.strptime(values, '%d/%m/%y %H:%M')) ds['sys_created_on'] = cleanedData return ds ##############################End cleanTheData################################################################
Output:Before the if else block created
in the else statement created
Before the if else block 4/4/2017 12:57
in the else statement 4/4/2017 12:57
Before the if else block 10/20/2016 11:28
in the else statement 10/20/2016 11:28
Before the if else block 3/29/2017 11:36
in the else statement 3/29/2017 11:36
Before the if else block 1/14/2017 8:41
in the else statement 1/14/2017 8:41