I'm trying to plot data from a textfile.
My data is in the form of:
2 - 5 6 6
4 - 5 6 7
6 - 5 6 3
8 - 5 6 3
1 0 - 5 6 4
1 2 - 5 6 4
1 4 - 5 6 3
Here is my terminal report up to the error in question:
>>> from matplotlib import pyplot
>>>
>>> time = []
>>> value = []
>>>
>>> source = open("textfile6.txt", "r")
>>>
>>> for line in source:
... line.replace(' ', '')
... t, v = line.split('-')
... time.append(int(t))
... value.append(int(v))
...
'2-566\n'
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
ValueError: invalid literal for int() with base 10: '5 6 6\n'
So the rationale is that I use str.replace(' ', '') in order to strip the white spaces (str.strip() was not achieving this for some reason!). Then I str.split('-') to break up my columns.
However I keep getting:
ValueError: invalid literal for int() with base 10: '5 6 6\n'
..as if white spaces have magically appeared back in the second string.