title: Create a Pandas DataFrame from deeply nested JSON
body: <p>I'm trying to create a single Pandas DataFrame object from a deeply nested JSON string. </p>
  
  <p>The JSON schema is:</p>
  
  <pre><code>{"intervals": [
  {
  pivots: "Jane Smith",
  "series": [
      {
          "interval_id": 0,
          "p_value": 1
         },
       {
           "interval_id": 1,
           "p_value": 1.1162791357932633e-8
       },
     {
          "interval_id": 2,
          "p_value": 0.0000028675012051504467
       }
      ],
     },
    {
  
  "pivots": "Bob Smith",
    "series": [
         {
              "interval_id": 0,
              "p_value": 1
             },
           {
               "interval_id": 1,
              "p_value": 1.1162791357932633e-8
           },
         {
              "interval_id": 2,
              "p_value": 0.0000028675012051504467
           }
         ]
       }
      ]
   }
  </code></pre>
  
  <p><strong>Desired Outcome</strong> I need to flatten this to produce a table:</p>
  
  <pre><code>Actor Interval_id Interval_id Interval_id ... 
  Jane Smith      1         1.1162        0.00000 ... 
  Bob Smith       1         1.1162        0.00000 ... 
  </code></pre>
  
  <p>The first column is the <code>Pivots</code> values, and the remaining columns are the values of the keys <code>interval_id</code> and <code>p_value</code> stored in the list <code>series</code>.</p>
  
  <p>So far i've got</p>
  
  <pre><code>import requests as r
  import pandas as pd
  actor_data = r.get("url/to/data").json['data']['intervals']
  df = pd.DataFrame(actor_data)
  </code></pre>
  
  <p><code>actor_data</code> is a list where the length is equal to the number of individuals ie <code>pivots.values()</code>. The df object simply returns</p>
  
  <pre><code>&lt;bound method DataFrame.describe of  pivots             Series
  0           Jane Smith  [{u'p_value': 1.0, u'interval_id': 0}, {u'p_va...
  1           Bob Smith  [{u'p_value': 1.0, u'interval_id': 0}, {u'p_va...
  .
  .
  .
  </code></pre>
  
  <p>How can I iterate through that <code>series</code> list to get to the dict values and create N distinct columns? Should I try to create a DataFrame for the <code>series</code> list, reshape it,and then do a column bind with the actor names? </p>
  
  <p>UPDATE:</p>
  
  <pre><code>pvalue_list = [i['p_value'] for i in json_data['series']]
  </code></pre>
  
  <p>this gives me a list of lists. Now I need to figure out how to add each list as a row in a DataFrame. </p>
  
  <pre><code>value_list = []
  for i in pvalue_list:
      pvs = [j['p_value'] for j in i]
      value_list = value_list.append(pvs)
  return value_list
  </code></pre>
  
  <p>This returns a NoneType</p>
  
  <p><strong>Solution</strong></p>
  
  <pre><code>def get_hypthesis_data():
      raw_data = r.get("/url/to/data").json()['data']
      actor_dict = {}
      for actor_series in raw_data['intervals']:
          actor = actor_series['pivots']
          p_values = []
          for interval in actor_series['series']:
              p_values.append(interval['p_value'])
          actor_dict[actor] = p_values
      return pd.DataFrame(actor_dict).T
  </code></pre>
  
  <p>This returns the correct DataFrame. I transposed it so the individuals were rows and not columns. </p>