4
我有一個3級的字典是這樣的:如何將3級詞典轉換爲所需的格式?
data={'2016-11-28': {'area1': {'am': -0.007, 'pm': 0.008}, 'area2': {'am': 0.0, 'pm': 0.0}, 'area3': {'am': -0.01, 'pm': -0.001}},'2016-11-29':{'area1': {'am': -0.007, 'pm': 0.008}, 'area2': {'am': 0.0, 'pm': 0.0}, 'area3': {'am': -0.01, 'pm': -0.001}}}
我想將它轉換成數據幀,而我想:
tickers=data['2016-11-28'].keys()
iterables=[tickers,['am','pm']]
index=pd.MultiIndex.from_product(iterables, names=['ticker', 'time'])
frame=pd.DataFrame(data,index=index)
,但我得到了
2016-11-28 2016-11-29
ticker time
area1 am NaN NaN
pm NaN NaN
area3 am NaN NaN
pm NaN NaN
area2 am NaN NaN
pm NaN NaN
有在數據框中沒有值,只有列名和索引名。我的代碼有什麼問題?有人可以幫忙嗎?非常感謝!
http://stackoverflow.com/questions/13575090/construct-pandas-dataframe-from-items-in-nested-dictionary – acushner