0

This type of question has been asked several times. Still, I can not find a similar issue to my case. If there is anything similar, please let me know.

The python file is

import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
import csv
import numpy as np

x = []
y = []

with open('example2.txt','r') as csvfile:
    plots = csv.reader(csvfile, delimiter=' ')
    for row in plots:
        #print(row[0],type(row[0]))
        x.append(float(row[0]))
        y.append(float(row[1]))

example2.txt is

0.0  0.5
0.1  0.6

I got an error message as

Traceback (most recent call last):
  File "plot.py", line 14, in <module>
    y.append(float(row[1]))
ValueError: could not convert string to float:

Some link, e.g., ValueError: could not convert string to float: id, suggests that the reason is, there is extra space in the value. I cannot find extra space by printing the row[0] values :(

AlphaF20
  • 583
  • 6
  • 14

0 Answers0