내가 다음 코드는 라인 (20)에이 오류가 발생지도 감소 -리스트 인덱스 범위를 벗어지도 매퍼에
#!/usr/bin/env python
import sys
myList = []
n = 10 # Number of top N records
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()
# split data values into list
data = line.split(";")
# convert weight (currently a string) to int
try:
balance = int(data[6])
except ValueError:
# ignore/discard this line
continue
# add (weight, record) touple to list
myList.append((balance, line))
# sort list in reverse order
myList.sort(reverse=True)
# keep only first N records
if len(myList) > n:
myList = myList[:n]
# Print top N records
for (k,v) in myList:
print(v)
mapperwith지도를 가지고 :
balance = int(data[6])
IndexError: list index out of range
프로세스가 존재하지 않는 파이프를 오른쪽으로 보려고했습니다.
age job marital education default balance housing loan contact day month duration campaign pdays previous poutcome y
30 unemployed married primary no 1787 no no cellular 19 oct 79 1 -1 0 unknown no
33 services married secondary no 4789 yes yes cellular 11 may 220 1 339 4 failure no
어떤 아이디어 : 여기
은 데이터 세트의 샘플입니다?
데이터가 공백으로 구분 된 경우 split ("\\ s +") 대신 –
@RAZ_Muh_Taz를 호출합니다. 여러 가지 다른 분할 및 동일한 결과를 시도했습니다. 내 코드에 또 다른 문제가 있습니까? –