title: Get an item value from a nested dictionary inside the rows of a pandas df and get rid off the rest
body: <p>I implemented <a href="https://demo.allennlp.org/open-information-extraction" rel="nofollow noreferrer">allennlp's OIE</a>, which extracts subject, predicate, object information (in the form of ARG0, V, ARG1 etc) embedded in nested strings. However, I need to make sure that each output is linked to the given <code>ID</code> of the original sentence.</p>
  <p>I produced the following pandas dataframe, where <code>OIE output</code> contains the raw output of the allennlp algorithm.</p>
  <p><strong>Current output:</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">sentence</th>
  <th style="text-align: center;">ID</th>
  <th style="text-align: right;">OIE output</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">'The girl went to the cinema'</td>
  <td style="text-align: center;">'abcd'</td>
  <td style="text-align: right;">{'verbs':[{'verb': 'went', 'description':'[ARG0: The girl] [V: went] [ARG1:to the cinema]'}]}</td>
  </tr>
  <tr>
  <td style="text-align: left;">'He is right and he is an engineer'</td>
  <td style="text-align: center;">'efgh'</td>
  <td style="text-align: right;">{'verbs':[{'verb': 'is', 'description':'[ARG0: He] [V: is] [ARG1:right]'}, {'verb': 'is', 'description':'[ARG0: He] [V: is] [ARG1:an engineer]'}]}</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>My code to get the above table:</p>
  <pre><code>oie_l = []
  
  for sent in sentences:
    oie_pred = predictor_oie.predict(sentence=sent) #allennlp oie predictor
    for d in oie_pred['verbs']: #get to the nested info
      d.pop('tags') #remove unnecessary info
    oie_l.append(oie_pred)
  
  df['OIE out'] = oie_l #add new column to df
  
  </code></pre>
  <p><strong>Desired output:</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">sentence</th>
  <th style="text-align: center;">ID</th>
  <th style="text-align: right;">OIE Triples</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">'The girl went to the cinema'</td>
  <td style="text-align: center;">'abcd'</td>
  <td style="text-align: right;">'[ARG0: The girl] [V: went] [ARG1:to the cinema]'</td>
  </tr>
  <tr>
  <td style="text-align: left;">'He is right and he is an engineer'</td>
  <td style="text-align: center;">'efgh'</td>
  <td style="text-align: right;">'[ARG0: He] [V: is] [ARG1:right]'</td>
  </tr>
  <tr>
  <td style="text-align: left;">'He is right and he is an engineer'</td>
  <td style="text-align: center;">'efgh'</td>
  <td style="text-align: right;">'[ARG0: He] [V: is] [ARG1:an engineer]'</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Approach idea:</p>
  <p>To get to the desired output of 'OIE Triples' , I was considering transforming the initial 'OIE output' into a string and then using regular expression to extract the ARGs. However, I am not sure if this is the best solution, as the 'ARGs' can vary. Another approach, would be to iterate to the nested values of  <code>description:</code> , replace what is currently in the OIE output in the form of a list and then implement <code>df.explode()</code> method to expand it, so that the right sentence and id columns are linked to the triple after 'exploding'.</p>
  <p>Any advice is appreciated.</p>