[{'info':{'price':'100',
'volume':'200000',
'ask':'101',
'bid':'99',
'fee':'0',
'spread':'2',},
'currency':'USD',
'ticker':'XYZ',
'timestamp':'1643123872',
'fee':{'cost':0, 'currency':'USD'}},
{'info':{'price':'107',
'volume':'220000',
'ask':'108',
'bid':'106',
'fee':'0',
'spread':'2',},
'currency':'USD',
'ticker':'XYZ',
'timestamp':'1643123882',
'fee':{'cost':0, 'currency':'USD'}}]
我想使用選擇鍵值創建具有上述資訊的資料框。所以我想生成一個如下所示的資料框:
df:
timestamp currency fee price ticker volume
1643123872 USD 0 100 XYZ 200000
1643123882 USD 0 107 XYZ 220000
如何才能做到這一點?請注意,我有“資訊”鍵的子鍵。
謝謝你。
uj5u.com熱心網友回復:
您可以使用.str訪問器從字典列中提取值。
假設data包含您的輸入串列:
df = pd.DataFrame(data)
df['price'] = df['info'].str['price']
df['volume'] = df['info'].str['volume']
df['fee'] = df['fee'].str['cost']
df[['timestamp', 'currency', 'fee', 'price', 'ticker', 'volume']]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/421082.html
標籤:
