두 개의 ID, 시작 및 종료 시간 및 GPS 좌표가있는 거대한 데이터가 있습니다. 나는 주파수, 합계, 평균, 평균, 최대, 최소, 접촉 시간 및 GPS 좌표를 기반으로하는 주파수를 찾으려고합니다.GPS 좌표가있는 Dict 조작
004096f41eb8 00904bf131ad 40.0 820219 438869 820219 438869
004096f41eb8 00904bf469bd 40.0 820219 438869 820219 438869
00022d56dffe 00022dcbe817 962.0 820353 439280 820353 439280
00022dcbe817 00306511e9e0 540.0 820353 439280 820353 439280
00022dcbe817 00904b21787a 4250.0 820353 439280 820353 439280
00022dcbe817 00904b3b845a 1117.0 820353 439280 820353 439280
00022dcbe817 00904bc3be80 1117.0 820353 439280 820353 439280
00022dcbe817 00904bcd5f00 4250.0 820353 439280 820353 439280
00022dcbe817 00904bfebc7c 3737.0 820353 439280 820353 439280
위의 내용은 입력 샘플입니다. col[0]
및 col[1]
은 ID입니다. ID에 관해서는 빈도, 합계, 평균, 중간 값, 최대 값, 최소값, 접촉 지속 시간을 찾을 수 있습니다. 그러나 ID 및 GPS 좌표를 모두 고려해야 할 때 아래 코드와 동일한 코드에이 코드를 포함 할 수 없습니다. 나는 동일한 GPS 좌표를 갖는 ID의 주파수를 찾아야한다.
예 : 대장균 [0] COL [1] 대장균 [3] 대장균 [4] 대장균 [5] 대장균 [6]
from collections import defaultdict
import numpy as np
pairtimelist = defaultdict(list)
pairgpslist = defaultdict(list)
with open('input', 'r') as f, open('output_all', 'w') as o_one, open('output_contact', 'w') as o_two, open('output_gps', 'w') as o_three:
for numline, line in enumerate((line.split() for line in f), start=1):
pair = line[0], line[1]
pairtimelist[pair].append(float(line[2]))
pairgps = line[0], line[1], line[3], line[4], line[5], line[6]
#pairgpslist[pairgps].append(float(line[2]))
for pair in pairtimelist.iterkeys():
timeavg = np.mean(pairtimelist[pair])
timemed = np.median(pairtimelist[pair])
timesum = np.sum(pairtimelist[pair])
timemax = np.max(pairtimelist[pair])
timemin = np.min(pairtimelist[pair])
freq = len(pairtimelist[pair])
for pairgps in pairgpslist.iterkeys():
freqgps = len(pairgpslist[pairgps]
#print pair, pairtimelist[pair]
o_two.write("%s %s \n" % (pair, pairtimelist[pair]))
o_one.write("%s %s %s %.2f %.2f %s %s %s \n" % (pair[0], pair[1], freq, timesum, timeavg, timemed, timemax, timemin))
o_three.write("%s %s \n" % (pair, freqgps))
Error:
File "pair_gps.py", line 21
o_two.write("%s %s \n" % (pair, pairtimelist[pair]))
^
SyntaxError: invalid syntax
그러나 오류가 보이지 않고 관련된 모든 GPS 주석 때 . 모두 함께 할 수있는 간단한 방법입니다. 미리 감사드립니다. 당신의 라인 19에서
아무도 도움을 요청하지 마십시오. 응답하지 마십시오. 그러나 '가까운'에 플래그를 지정하지 않으면 귀하에게 중요하지 않을 수 있습니다. 이 문제에 대한 도움을 얻으십시오. –