I have a file 'data.csv' that looks something like
ColA, ColB, ColC 1,2,3 4,5,6 7,8,9 I want to open and read the file columns into lists, with the 1st entry of that list omitted, e.g.
dataA = [1,4,7] dataB = [2,5,8] dataC = [3,6,9] In reality there are more than 3 columns and the lists are very long, this is just an example of the format. I've tried:
csv_file = open('data.csv','rb') csv_array = [] for row in csv.reader(csv_file, delimiter=','): csv_array.append(row) Where I would then allocate each index of csv_array to a list, e.g.
dataA = [int(i) for i in csv_array[0]] But I'm getting errors:
_csv.Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode? Also it feels like a very long winded way of just saving data to a few lists...
Thanks!
edit:
Here is how I solved it:
import pandas as pd df = pd.read_csv('data.csv', names = ['ColA','ColB','ColC'] dataA = map(int,(df.ColA.tolist())[1:3]) and repeat for the rest of the columns.