-1
我有了許多列發現其中一個速配關鍵字是一個CSV文件使用python
這裏的CSV文件中使用的所有實例是Excel文件的樣子 http://i.stack.imgur.com/AB6TP.png
我需要的圖像查看成千上萬行,在標記爲Hit Definition的列中查找任何名稱爲「grapevine」的病毒。 對於名稱爲「grapevine」的每個單詞,我需要編譯它提及的次數,長度範圍(列標記爲查詢長度,[2])和讀取總和(列總讀數,[4] )。
輸入: http://i.stack.imgur.com/AB6TP.png
輸出:
葡萄1 6 234-234234 45634
葡萄2 7 123-65432 12341
with open(argv[1], 'r') as f:
for line in csv.reader(f):
contig_name = line[0]
contig_length = line[3]
read_count = line[4]
hit_def = line[6]
try:
pattern = r'.\[(.*?)\].'
hit_sub = re.search(pattern, hit_def).group(1)
print hit_sub
except AttributeError:
hit_sub = hit_def
target.append([hit_sub])
這就是我到目前爲止 我迷失在如何篩選名稱
你的模式是沒有意義的你的問題,也總結和line.count(」葡萄藤「)可能是足夠的 –