저는 파이썬에 매우 익숙합니다. 저는 수 문학 분야에서 일하고 있습니다. 저는 수 문학 데이터 처리를 돕기 위해 파이썬을 배우고 싶습니다.파이썬 스크립트의 속도를 향상시키는 방법
지금은 큰 데이터 세트에서 정보 비트를 추출하는 스크립트를 작성합니다. 나는 3 개 CSV 파일이 있습니다
Complete_borelist.csv을
Borelist_not_interested.csv
Elevation_info.csv
complete_borelist.csv에 있지만 모든 구멍을 가지고와 나는 파일을 만들려면 in borelist_not_interested.csv. 또한 첫 번째 기준을 충족하는 보어에 대해 complete_borelist.csv 및 Elevation_info.csv에서 일부 정보를 가져 오려고합니다.
첫 번째는 Complete_borelist.csv에있는 모든 구멍에 대한 정보를 가지고 있지 않은 Elevation_info.csv입니다 :
not_interested_list =[]
outfile1 = open('output.csv','w')
outfile1.write('Station_ID,Name,Easting,Northing,Location_name,Elevation')
outfile1.write('\n')
with open ('Borelist_not_interested.csv','r') as f1:
for line in f1:
if not line.startswith('Station'): #ignore header
line = line.rstrip()
words = line.split(',')
station = words[0]
not_interested_list.append(station)
with open('Complete_borelist.csv','r') as f2:
next(f2) #ignore header
for line in f2:
line= line.rstrip()
words = line.split(',')
station = words[0]
if not station in not_interested_list:
loc_name = words[1]
easting = words[4]
northing = words[5]
outfile1.write(station+','+easting+','+northing+','+loc_name+',')
with open ('Elevation_info.csv','r') as f3:
next(f3) #ignore header
for line in f3:
line = line.rstrip()
data = line.split(',')
bore_id = data[0]
if bore_id == station:
elevation = data[4]
outfile1.write(elevation)
outfile1.write ('\n')
outfile1.close()
내가 스크립트 두 가지 문제가 있습니다
내 스크립트는 다음과 같다 . 내 루프가 Elevation 레코드를 찾을 수없는 스테이션에 도달하면 스크립트는 "null"을 쓰지 않지만 같은 라인의 다음 스테이션에 대한 정보를 계속 작성합니다. 누구든지이 문제를 해결하도록 도와 줄 수 있습니까?
둘째로 내 보링리스트는 약 200,000 개가 넘고 내 스크립트는 매우 느리게 실행됩니다. 누구든지 더 빨리 달릴 수있는 제안이 있습니까?
제 질문이 너무 길면 대단히 감사합니다.
대단히 감사합니다. 그것은 지금 몇 초 안에 작동합니다 :) – mikayla