I’m using an automatic data acquisition software that exports the data as .txt files. I then imported the file into python (using the pandas package and turning the columns into arrays) but I’m facing a problem. Python can’t “read” the data because the automatic data acquisition software exported it into the following number format, and so Python is treating each entry of the array as a string instead of a number:
Is there any way I can “teach” python to read my data? Or to automatically rewrite the entries in the array so they’re read as numbers?
Advertisement
Answer
You can simply change the comma in the strings with a dot and use float()
to parse it.
number = float('7,025985E-36'.replace(',', '.')) print(number) print(type(number))
The above code would print:
7.025985e-36 <class 'float'>