python 2.7 - Read in multiple columns with csv readin -


maybe being picky matlab user trying convert having trouble importing data. can't seem read in more 2 columns of data csv read in. here coding using

x,y = [],[] csv_reader = csv.reader(open('data.csv')) line in csv_reader:     x.append(line[0])     y.append(line[1]) 

if use data.csv more 2 columns, can't seem return 3rd column , have read in several csv files data want.

i bring point using csv format because can't figure out how import else. again, previous matlab user, prefer copy spreadsheet .txt file , import that. direction on appreciated. much

this worked fine me long kept adding variables, i.e. z=[] , z.append(line[2]), , on... maybe misunderstanding questions?

import csv x,y,z = [],[],[] csv_reader = csv.reader(open('data.csv')) line in csv_reader:     x.append(line[0])     y.append(line[1])     z.append(line[2]) 

if copy spreadsheet , paste text file, can open('data.txt') , split each line \t, if separator between columns.

xx,yy,zz = [],[],[] fromtextfile = open('data.txt') #(append each list)   #item in line, split tabs, list line in file [(xx.append(item[0]),yy.append(item[1]),zz.append(item[2])) \  item in [line[:-1].split('\t') line in fromtextfile]]  #or  xxx,yyy,zzz = [],[],[] fromtextfile = open('data.txt') temp = [] line in fromtextfile:     temp.append(line[:-1]) item in temp:     templist = item.split('\t')     xxx.append(templist[0])     yyy.append(templist[1])     zzz.append(templist[2])  fromtextfile.close() 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -