OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

how to get list of values from nested panda dictionary and insert it in to a column [duplicate]

  • Thread starter Thread starter mona
  • Start date Start date
M

mona

Guest
I have a nested dictionary which looks like following:

Code:
  {'NSE_FO:NIFTY28DEC21000CE': {'ohlc': None,
  'depth': {'buy': [{'quantity': 0, 'price': 0.0, 'orders': 0},
    {'quantity': 1, 'price': 3.0, 'orders': 1},
    {'quantity': 1, 'price': 3.0, 'orders': 1}],
   'sell': [{'quantity': 0, 'price': 0.0, 'orders': 0},
    {'quantity': 1, 'price': 3.0, 'orders': 1},
    {'quantity': 1, 'price': 3.0, 'orders': 1}]},
  },
 'NSE_FO:NIFTY28DEC24000CE': {'ohlc': None,
  'depth': {'buy': [{'quantity': 1, 'price': 3.0, 'orders': 0},
    {'quantity': 1, 'price': 1.0, 'orders': 1},
    {'quantity': 2, 'price': 2.0, 'orders': 1}],
   'sell': [{'quantity': 0, 'price': 0.0, 'orders': 0},
    {'quantity': 3, 'price': 3.0, 'orders': 1},
    {'quantity': 4, 'price': 4.0, 'orders': 1}]},
  },
 'NSE_FO:NIFTY28DEC28000PE': {'ohlc': {'open': 0.0,
   'high': 0.0,
   'low': 0.0,
   'close': 0.0},
  'depth': {'buy': [{'quantity': 250, 'price': 1040.05, 'orders': 1},
    {'quantity': 4, 'price': 1.0, 'orders': 1},
    {'quantity': 2, 'price': 3.0, 'orders': 1}],
   'sell': [{'quantity': 0, 'price': 0.0, 'orders': 1},
    {'quantity': 3, 'price': 3.0, 'orders': 1},
    {'quantity': 4, 'price': 4.0, 'orders': 1}]},
  }}

i want to extract the 1st price value from depth->buy->price of each NSE_FO:NIFTY28DEC24000CE' without using loop and insert it into a new column. is it possible?

desired output :

Code:
0.0
3.0
1040.05
<p>I have a nested dictionary which looks like following:</p>
<pre><code> {'NSE_FO:NIFTY28DEC21000CE': {'ohlc': None,
'depth': {'buy': [{'quantity': 0, 'price': 0.0, 'orders': 0},
{'quantity': 1, 'price': 3.0, 'orders': 1},
{'quantity': 1, 'price': 3.0, 'orders': 1}],
'sell': [{'quantity': 0, 'price': 0.0, 'orders': 0},
{'quantity': 1, 'price': 3.0, 'orders': 1},
{'quantity': 1, 'price': 3.0, 'orders': 1}]},
},
'NSE_FO:NIFTY28DEC24000CE': {'ohlc': None,
'depth': {'buy': [{'quantity': 1, 'price': 3.0, 'orders': 0},
{'quantity': 1, 'price': 1.0, 'orders': 1},
{'quantity': 2, 'price': 2.0, 'orders': 1}],
'sell': [{'quantity': 0, 'price': 0.0, 'orders': 0},
{'quantity': 3, 'price': 3.0, 'orders': 1},
{'quantity': 4, 'price': 4.0, 'orders': 1}]},
},
'NSE_FO:NIFTY28DEC28000PE': {'ohlc': {'open': 0.0,
'high': 0.0,
'low': 0.0,
'close': 0.0},
'depth': {'buy': [{'quantity': 250, 'price': 1040.05, 'orders': 1},
{'quantity': 4, 'price': 1.0, 'orders': 1},
{'quantity': 2, 'price': 3.0, 'orders': 1}],
'sell': [{'quantity': 0, 'price': 0.0, 'orders': 1},
{'quantity': 3, 'price': 3.0, 'orders': 1},
{'quantity': 4, 'price': 4.0, 'orders': 1}]},
}}
</code></pre>
<p>i want to extract the 1st price value from depth->buy->price of each NSE_FO:NIFTY28DEC24000CE' without using loop and insert it into a new column. is it possible?</p>
<p>desired output :</p>
<pre><code>0.0
3.0
1040.05


</code></pre>
 
Top