I'm reading in a csv file, and all rows contain string elements. One might be:
"orange", "2", "65", "banana"
I want to change this, within my dataset, to become:
row = ["orange", 2.0, 65.0, "banana"]
Here is my code:
data = f.read().split("\n")
for row in data:
for x in row:
if x.isdigit():
x = float(x)
print row
But it still prints the original rows like:
"orange", "2", "65", "banana"
I also want to achieve this without using list comprehensions (for now).