我的數據是這樣的:轉換一個字典的熊貓數據幀
{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"}'}
我想將其轉換爲大熊貓數據幀。但是,當我嘗試
df = pd.DataFrame(response.items())
我與兩列的數據幀時,先用第一個關鍵,第二個與鍵的值:
0 1
0 "57e01311817bc367c030b390" {"ad_since": 2016, "indoor_swimming_pool": "No...
1 "57e01311817bc367c030b3a8" {"ad_since": 2012, "indoor_swimming_pool": "No...
我怎樣才能得到一個列對於每個鍵:"ad_since"
,"indoor_swimming_pool"
,"indoor_swimming_pool"
?並保留第一列,或者將id作爲索引。
嘗試read_json http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.read_json.html –
您是否嘗試使用'pd.DataFrame(response.items())' ?對我來說,它不工作。 – jezrael
@jezrael感謝您的評論,我編輯我的帖子 – mitsi