Aashish sharma Sharma - 3 months ago 31

Python Question

I have CSV file which has 2 columns. Time, Value. I want to read value, say corresponding to 104 nanoseconds but problem is Time is in exponential format and power of exponent keep on changing to ensure that there is just one digit before the decimal. Example.

- 9.829581682732399e-08
- 9.832266867048999e-08
- 1.00221920509641e-07
- 1.04344516783252e-07

One way is I read entire column then read last 2 digit and see how many nanoseconds it is. Is there a 'Pythonian' way to do this more quickly?

Answer

Assuming your exponential values are numbers and not strings, exponential values are valid floats, so you could just multiply the values in the column by 10^9 for nano seconds

for example:

```
6.e-07 * 1000000000
```

would give you 600

if it is a string, then you can just cast it to a float:

```
float("6.e-07") * 1000000000
```