[問題] 大量資料程式抓取
大家好,我想在一個csv裡面
抓取可能只出現的一筆的那一行資料(或兩筆、三筆)
我寫了一個code,希望能用最快的速度將資料抓出來
已經在server上跑了結果似乎是卡住了?
目前問題: 有試過比較小資料量的資料,跑出來是可以的
可能是我的資料量太大,因此他跑到出現我設定的"start output"就靜止在那邊了
以下是我的code:
import csv
from collections import defaultdict
protein_table = defaultdict(list)
P = []
a = int(raw_input("times: "))
out = str(a+1) + " domain protein.csv"
o = open(out,"w")
f = open("multiple domain protein.csv","r")
for row in csv.reader(f):
P.append(row[1])
protein_table[row[1]].append(row[0]+","+row[1]+","+row[2]+","+row[3]+","+row[4]+"\n")
print "----------------------start output-------------------"
for i in [k for k in P if P.count(k)==a]:
if i in protein_table:
for protein in protein_table[i]:
o.write(protein)
o.flush()
o.close()
f.close()
請問大家有什麼比較好修改的地方嗎?
還是得寫跑比較久的迴圈之類的
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.126.36.171
※ 文章網址: http://www.ptt.cc/bbs/Python/M.1419239375.A.EE5.html
→
12/22 18:16, , 1F
12/22 18:16, 1F
→
12/22 18:16, , 2F
12/22 18:16, 2F
→
12/22 18:16, , 3F
12/22 18:16, 3F
→
12/22 18:16, , 4F
12/22 18:16, 4F
→
12/22 18:16, , 5F
12/22 18:16, 5F
→
12/22 18:17, , 6F
12/22 18:17, 6F
→
12/22 18:18, , 7F
12/22 18:18, 7F
→
12/22 18:18, , 8F
12/22 18:18, 8F
→
12/22 18:25, , 9F
12/22 18:25, 9F
→
12/22 18:26, , 10F
12/22 18:26, 10F
推
12/23 08:25, , 11F
12/23 08:25, 11F
推
01/26 22:18, , 12F
01/26 22:18, 12F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
2
12
Python 近期熱門文章
PTT數位生活區 即時熱門文章