I'm rather new to python and I'm not sure how to do the following.
I have a list foo containing metadata and measurement values for a certain plot. For example, a plotID, survey date, initials of surveyors, several measurement values and a categorical variable.
foo= ['plot001', '01-01-2013', 'XX', '10', '12.5', '0.65', 'A'] Because these data are read from a .txt, all list items are strings. My question is: how do I convert each list item to the approporiate datatype?. I can make a list with the desired data types:
dType= ['str', 'str', 'str', 'int', 'float', 'float', 'float', 'str'] It would be nice if I could apply each item in dType as function to the matching element in foo as such:
out= [str(foo[0]), str(foo[1]), str(foo[2]), int(foo[3]), float(foo[4]), float(foo[5]), float(foo[6]), str(foo[7])] but I'm sure there must be a better solution! Thanks for any suggestions!