I am using xlrd
to parse a .xlsx
file to a JSON format. I encountered a problem with commas and dots..
The value which I entered into my Excel file: 152,203
. I would like to parse this into a value of: 152.203
, but no luck yet. It saves the value as 152
which is a problem. In Dutch commas are often used as dots, so this mistake has to be caught.
Partial code example:
key3 = OrderedDict()
row_values3 = sheet.col_values(1, 0, 60)
comma_to_dot = row_values3[36] # cell with 152,203
key3['Value'] = comma_to_dot.replace(",",".")
data.append(key3)
j = json.dumps(data)
with open(full_path, 'w') as datafile:
datafile.write(j)
print(full_path)
This code give the error: AttributeError: 'float' object has no attribute 'replace'
I have also tried:
key3['Value'] = int(row_values3[36])
But this also returns 152