-1
我正在對csv文件進行一些過濾,其中每個標題都有許多具有不同預測值的重複ID,所以第2列(pythoniac)是不同的。我想只保留30個最低值,但具有唯一的ID。我來到這個代碼,但我不知道如何保持最低的30個條目。Python:保持csv.reader的頂部Nth結果
你能幫我們建議如何獲得30個獨特的ID條目?
# title1 id1 100 7.78E-25 # example of the line
with open("test.txt") as fi:
cmp = {}
for R in csv.reader(fi, delimiter='\t'):
for L in ligands:
newR = R[0], R[1]
if R[0] == L:
if (int(R[2]) <= int(1000) and int(R[2]) != int(0) and float(R[3]) < float("1.0e-10")):
if newR in cmp:
if float(cmp[newR][3]) > float(R[3]):
cmp[newR] = R[:-2]
else:
cmp[newR] = R[:-2]