2014-03-26 9 views
1

텍스트 파일 (pandas 사용)에서 데이터를로드하고 열의 값을 확인하는 Python 스크립트 (아래)를 작성했습니다.키 오류 및 팬더

import sys 
import pandas as pd 
import numpy as np 
from numpy import ndarray 
import math 
import matplotlib.pyplot as plt 
from matplotlib.pyplot import * 
from skimage import data 
from skimage.feature import match_template 

if __name__ == '__main__': 
    data = pd.read_csv('Fe_PSI_spt_refined.txt', sep=" ", header = None) 
    data.columns = ["Angle_number", "Omega", "Intensity", "X", "Y", "Address", "ID"]#, "flag"] 
    Number_of_projections = 181 
    Number_of_lines_in_txt = 3493 
    numrows = len(data) 
    counter_array = [] 
    correlation_threshold_value = 0.7 
    a = np.zeros(Number_of_lines_in_txt) 
    output_file = ("output.txt") 

    for i in range(2, (Number_of_projections + 1)): 
     filename_cutouts_combined = ("cutouts_combined_%03i.txt" % (i)) 
     filename_cutouts_combined_tag = ("cutouts_combined_tag_%03i.txt" % (i)) 
     image = np.loadtxt(filename_cutouts_combined) 
     image_tagged = np.loadtxt(filename_cutouts_combined_tag) 
     for j in range(0, Number_of_lines_in_txt - 1): 
      print data.Angle_number[j], i 

j 중 하나 반복 후 나는 아래의 오류가 발생합니다. 내가 고쳐야 할 어떤 오류라도 찾아 낼 수 있니? a 사용하지 않는 남아있는 동안 감사

`Traceback (most recent call last): 
    File "Hyperbola_search.py", line 46, in <module> 
    print data.Angle_number[j], i 
    File "/Users/Alberto/anaconda/lib/python2.7/site-packages/pandas/core/series.py", line 491, in __getitem__ 
    result = self.index.get_value(self, key) 
    File "/Users/Alberto/anaconda/lib/python2.7/site-packages/pandas/core/index.py", line 1032, in get_value 
    return self._engine.get_value(s, k) 
    File "index.pyx", line 97, in pandas.index.IndexEngine.get_value (pandas/index.c:2661) 
    File "index.pyx", line 105, in pandas.index.IndexEngine.get_value (pandas/index.c:2476) 
    File "index.pyx", line 149, in pandas.index.IndexEngine.get_loc (pandas/index.c:3215) 
    File "hashtable.pyx", line 382, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6450) 
    File "hashtable.pyx", line 388, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:6394) 
KeyError: 3491` 

답변

0

당신은, imageimage_tagged에 파일을로드합니다.

data.Angle_numbernumrows은 무엇인지 모르겠지만 라이브러리와 관련이 있으며 파일과 관련이 없습니다.

+0

안녕하세요. Lorenzo, 제가 코드를 너무 단순화했습니다 ... 위의 업데이트 된 버전에서 데이터가 txt ('__name__ == '__main __':'아래의 첫 번째 두 줄 참조)를 읽지 못합니다. –