Convert a dict to a pandas DataFrame
<p>My data look like this : </p>

<pre><code>{u'"57e01311817bc367c030b390"': u'{"ad_since": 2016, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access": "Yes"}', u'"57e01311817bc367c030b3a8"': u'{"ad_since": 2012, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access": "Yes"}'}
</code></pre>

<p>I want to convert it to a pandas Dataframe. But when I try </p>

<pre><code>df = pd.DataFrame(response.items())
</code></pre>

<p>I get a DataFrame with two columns, the first with the first key, and the second with the values of the key: </p>

<pre><code>                            0                       1 
0  "57e01311817bc367c030b390"   {"ad_since": 2016, "indoor_swimming_pool": "No...
1  "57e01311817bc367c030b3a8"   {"ad_since": 2012, "indoor_swimming_pool": "No... 
</code></pre>

<p>How can I get a single column for each key : <code>"ad_since"</code>, <code>"indoor_swimming_pool"</code>, <code>"indoor_swimming_pool"</code> ? And keep the first column, or get the id as index.</p>

<p>As the values are strings, you can use the <a href="https://docs.python.org/2/library/json.html" rel="nofollow"><code>json</code> module</a> and list comprehension:</p>

<pre><code>In [20]: d =     {u'"57e01311817bc367c030b390"': u'{"ad_since": 2016, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access": "Yes"}', u'"57e01311817bc367c030b3a8"': u'{"ad_since": 2012, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access": "Yes"}'}

In [21]: import json

In [22]: pd.DataFrame(dict([(k, [json.loads(e)[k] for e in d.values()]) for k in json.loads(d.values()[0])]), index=d.keys())Out[22]: 
                            ad_since handicapped_access indoor_swimming_pool  \
"57e01311817bc367c030b390"      2016                Yes                   No   
"57e01311817bc367c030b3a8"      2012                Yes                   No   

                       seaside  
"57e01311817bc367c030b390"      No  
"57e01311817bc367c030b3a8"      No  
</code></pre>

python json pandas