I have a .csv
file in which data is separated by commas and I want to separate it into columns. For this, I am trying to put every row element in a list and then put them into columns in a new file. The code I'm using is the following:
import csv
c1 = []
c2 = []
c3 = []
with open('File.csv', 'r') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
c1.append(row[0])
c1.append(row[1])
c1.append(row[2])
For some reason, I am able to store in c1 just the column of the .csv file. For c2 and c3 I'm getting an error. It seems like "reader" jumps into the next row right after getting the first element of the current row. Could somebody give me an idea? Perhaps there is even an easier way to do it?