Python pandas extract values from dict within a list
<p>Basically I would like to extract price value from this column, but the problem that if I use index [0] it would bring index[0] error in line 11 and price key also does not exit in this line.</p>

<pre><code>ex
0    {u'availableToBack': [{u 'price' : 1.02, u 'size' : 2.15}], u 'availableToLay' : [], u 'tradedVolume' : []}
1    {u'availableToBack': [{u'price': 6.8, u'size':...
2    {u'availableToBack': [{u'price': 8.2, u'size':...
3    {u'availableToBack': [{u'price': 9.6, u'size':...
10   {u'availableToBack': [{u'price': 70.0, u'size'...
11   {u'availableToBack': [], u'availableToLay': []...
12   {u'availableToBack': [], u'availableToLay': []...
</code></pre>

<p>I use something like this</p>

<pre><code>table['price'] = table['ex']['availableToBack'][0].apply(lambda x: x.get('price'))
</code></pre>

<p>Can you help me how to go around it, please?</p>

<p>JSON looks like this:</p>

<pre><code>    u 'runners' : [{
            u 'status' : u 'ACTIVE',
            u 'handicap' : 0.0,
            u 'selectionId' : 10861647,
            u 'totalMatched' : 0.0,
            u 'adjustmentFactor' : 16.631,
            u 'ex' : {
                u 'availableToBack' : [{
                        u 'price' : 1.02,
                        u 'size' : 2.15
                    }
                ],
                u 'availableToLay' : [],
                u 'tradedVolume' : []
            }
        }, {
            u 'status' : u 'ACTIVE',
            u 'handicap' : 0.0,
            u 'selectionId' : 10861648,
            u 'totalMatched' : 0.0,
            u 'adjustmentFactor' : 13.237,
            u 'ex' : {
                u 'availableToBack' : [{
                        u 'price' : 1.01,
                        u 'size' : 7.11
                    }
                ],
                u 'availableToLay' : [],
                u 'tradedVolume' : []
            }
        },
</code></pre>