Reputation: 349
I have a .csv file with data like this:
uc007ayl.1,ENSMUSG00000041439
uc009mkn.1,ENSMUSG00000031708
uc009mkn.1,ENSMUSG00000035491
I have some codes that read them column by column
import csv
import os.path
#open files + readlines
with open("C:/Users/Ivan Wong/Desktop/Placement/Lists of targets/Mouse/UCSC to Ensembl.csv", "r") as f:
reader = csv.reader(f, delimiter = ',')
#find files with the name in 1st row
for row in reader:
graph_filename = os.path.join("C:/Users/Ivan Wong/Desktop/Placement/Interesting reading/3'ORF",row[0]+"_nt_counts.txt.png")
if os.path.exists(graph_filename):
y = row[0]+'_nt_counts.txt'
r = open('C:/Users/Ivan Wong/Desktop/Placement/fp_mesc_nochx/'+y, 'r')
k = r.readlines()
r.close
del k[:1]
k = map(lambda s: s.strip(), k)
interger = map(int, k)
import iter
tools
#adding the numbers for every 3 rows
def grouper(n, iterable, fillvalue=None):
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return itertools.izip_longest(*args, fillvalue=fillvalue)
result = map(sum, grouper(3, interger, 0))
e = row[1]
Now I can say
print row[1]
to make it show the 2nd column only. I needed to do this because I will be finding these names in another file. But I have a problem because I think python is reading those names in this way:
"E", "N", "S", "M", "U", "S" etc.
This causes a problem now because I won't able to find the match names from another folder. Anyone know where is the problem and how to fix it?
Upvotes: 1
Views: 143
Reputation: 414149
row[1]
is not the whole second column of the file. It is just the second field in the current row i.e., just one of many values in the second column.
row[1]
is a string in your case. Strings in Python are also sequences; you can call len(some_string)
to find out length of string, take an element at a given position pos
: some_string[pos]
, etc.
Upvotes: 2