I'm pulling in a data file with key value pairs where the data is raw and starts as a string. I created this function to pass the value of the key value pair to check what data type it is.
I created this function to tag that value and convert it to the appropriate datatype as needed.
Is this the best way to handle this, or is there a library or function already included with python that's faster, or more efficient?
import dateparser
def dataType(value):
try:
int(value)
return 'INTEGER'
except ValueError:
try:
float(value)
return 'DOUBLE'
except ValueError:
try:
if value and value[0].isdigit():
dateparser.parse(value, settings={'STRICT_PARSING': True})
return 'DATETIME'
else:
return 'VARCHAR'
except ValueError:
return 'VARCHAR'