Reputation: 43
I've imported a csv file which all contain decimals with exponents for example (5.5006250364943992**02). I keep getting ValueError: could not convert string to float
. This is what I have done:
import matplotlib.pyplot as plt
import csv
x = []
y = []
with open('DNSdata.csv', 'r') as csvfile:
plots = csv.reader(csvfile, delimiter=',')
for row in plots:
x.append(float(row[0]))
y.append(float(row[1]))
plt.plot(x, y, label='DNSdata')
plt.xlabel('x')
plt.ylabel('y')
plt.title('DNSdata')
plt.show()
Upvotes: 3
Views: 1532
Reputation: 84
Is the Syntax you wrote the Syntax that is used in the file? I don't think Python can intepret "5.5**02".
If by "**" mean "10^" then you would need to manually make that replacement.
tmp = row[0].replace("**","e")
x.append(tmp)
Upvotes: 4