关键错误&熊猫

时间:2014-03-26 15:28:16

标签: python matplotlib pandas keyerror

我写了一个Python脚本(下面),它从文本文件加载数据(使用pandas)并检查列中的值。

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的一次迭代之后,我得到以下错误。你发现我应该修复的任何错误吗?感谢

`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`

1 个答案:

答案 0 :(得分:0)

您将文件加载到imageimage_tagged,而a仍未使用。

我不知道data.Angle_numbernumrows是什么,但它们似乎来自库,与您的文件无关。