I have a dictionary stored as numpy array a typical key is in the format of
<p>I have a dictionary of data stored as a numpy array. A typical key in the dictionary is in the format of:</p>

<pre><code>('Typical Key', {'a': 100 'b': 'NaN', 'c': 'NaN', 'e': 360300, 'f': 8308552, 'g': 'NaN', 'h': 3576206, 'i': True, 'j': 'NaN', 'k': 'NaN', 'l': 'NaN', 'm': 'blah.blah@blah.com', 'x': 'NaN'})
</code></pre>

<p>I am trying to find which key in the dictionary contains an element with the maximum value in order to identify an outlier in my dataset which I can see on a graph. I know what the key of the data point SHOULD be from working through a tutorial (I know the answer)</p>

<p>I have tried a few ways of doing this but I'm consistently getting an unexpected result - I have been basing my code around using <code>max()</code> function. For instance see examples below:</p>

<pre><code>inverse = [(value, key) for key, value in data_dict.items()]
print max(inverse)[1]

xx = max(data_dict, key=lambda i: data_dict[i])

print xx

import operator 
result = max(data_dict.iteritems(), key=operator.itemgetter(1))[0]
print result
</code></pre>

<p>I have a feeling that I'm not looking at the elements and that's the problem. Any help is appreciated!</p>

<p>O.K sorted it by tweaking the code proplerly - possibly because i had not articulated what i wanted to do properly
Had to tweak the code slightly but this did work - i need to work to understand why my other code was not returning the expected value </p>

<pre><code>import sys
Max = -sys.maxint
best_key = None
    for k, v in data_dict.iteritems():
    # k refers to each 'typical key'
  inner_dict = v
      for key, value in inner_dict.iteritems():
          if isinstance(value, int) and Max &lt; value:
          Max = value
          best_key = k`
</code></pre>

python pandas numpy dictionary regression