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?
csv.readerthat the delimiter is','when there don't seem to be any commas in your text file?' 'or by','?print row[1]but your code doesn't mention arow. Could you edit your question to include the code you're actually using? [Incidentally, does your filename really have two asterisks in it?]