It's worth noting that you should try using the with statement when opening files in Python. This is more readable and removes the possibility that the file remains open (even if exceptions occur).
Your real problem is that you are not doing what you want.
reader = csv.reader(filein, skipinitialspace = True) listofxys = [] for row in reader: listofxys.append(row)
All this makes reader = list(csv.reader(filein, skipinitialspace = True)) very inefficient.
What you want to do is use zip() builtin to take a list of pairs and turn it into two lists. You do this with the star operator:
import csv with open("test") as filein: reader = csv.reader(filein, skipinitialspace = True) xs, ys = zip(*reader) print(xs) print(ys)
What gives:
('10', '2', '5', '7', '9', '3', '2', '6', '0', '5') ('5', '4', '6', '8', '12', '45', '4', '5', '3', '6')
Note that these values ββare strings. If you want to have them as numbers, you will want to use csv.QUOTE_NONNUMERIC , for example: reader = csv.reader(filein, quoting=csv.QUOTE_NONNUMERIC, skipinitialspace = True)
What gives:
(10.0, 2.0, 5.0, 7.0, 9.0, 3.0, 2.0, 6.0, 0.0, 5.0) (5.0, 4.0, 6.0, 8.0, 12.0, 45.0, 4.0, 5.0, 3.0, 6.0)