title: Reformat list of nested dictionaries formatted as string
body: <p>I am trying to get data (from a mongo database), that has one nested attribute.</p>
  <p>The collection was turned into a pandas dataframe that I have access to. Every row represents an event that can be accompanied by no, one or several activities that are stored as a list of dictionaries within an attribute at every row, however formatted as a string:</p>
  <pre class="lang-py prettyprint-override"><code>all_users_activities = all_data[all_data[&quot;activities&quot;] != &quot;[]&quot;]
  all_users_activities_list = all_users_activities[&quot;activities&quot;].tolist()
  all_users_activities_list = [
      {
          &quot;attributes&quot;: {
              &quot;cost&quot;: [&quot;none, none&quot;],
              &quot;spent&quot;: 20,
              &quot;duration&quot;: 20,
              &quot;partners&quot;: &quot;Yes&quot;,
          },
          &quot;uid&quot;: &quot;53&quot;,
          &quot;id&quot;: &quot;0013&quot;,
      },
      {
          &quot;attributes&quot;: {&quot;cost&quot;: [&quot;none, none&quot;], &quot;duration&quot;: 10, &quot;partners&quot;: &quot;No&quot;},
          &quot;uid&quot;: &quot;23&quot;,
          &quot;activity&quot;: &quot;0002&quot;,
      },
  ]
  </code></pre>
  <p>I'm currently turning it into a working lists of dicts and in turn a dataframe with the desired attributes (id and duration) like this, messily:</p>
  <pre class="lang-py prettyprint-override"><code>acts = []
  for t in all_users_activities_list:
      t = t.replace(&quot;}&quot;, &quot;}}&quot;).replace(&quot;{&quot;, &quot;{{&quot;)
      t = t.split(&quot;}, {&quot;)
      t = [
          x.replace(&quot;}}&quot;, &quot;}&quot;).replace(&quot;{{&quot;, &quot;{&quot;).replace(&quot;[{&quot;, &quot;{&quot;).replace(&quot;}]&quot;, &quot;}&quot;)
          for x in t
      ]
      for i in t:
          print((&quot;t: &quot;, i))
      t = [ast.literal_eval(x) for x in t]
      for i in t:
          elm = [i[&quot;_id&quot;], i[&quot;attributes&quot;][&quot;duration&quot;]]
          acts.append(elm)
  
  actsummary = pd.DataFrame(acts, columns=[&quot;id&quot;, &quot;duration&quot;])
  </code></pre>
  <p>What better way to achieve this is there? Do I necessarily need to access the MondoDB through my server run Python script?</p>