So I need to convert the data where a value looks like a number into a numeric value:
Code: Select all
data = {
'a':"1",
'b':True,
'c':11.22,
'd':"22.11",
'e':"Hello World 1234"
}
for key in data:
try:
if(not type(data[key])==bool):
data[key] = float(data[key])
if(data[key]%1==0):
data[key] = int(data[key])
except:
continue
print(data)
> {'d': 22.11, 'e': 'Hello World 1234', 'c': 11.22, 'a': 1, 'b': True}