Reputation: 98881
I've a dictionary
containing multiple dictionaries that I'd like to insert on a dataframe
, i.e.:
{{u'USDT_REP': {'quoteVolume60m': 0, 'last': u'28.21000141', 'close60m': 0, 'close5m': u'28.21000141', 'close30m': u'28.71000004', 'close8h': u'30.17823249', 'quoteVolume30m': u'9.98429023', 'close24h': u'34.5', 'quoteVolume': u'8667.24172620', 'quoteVolume5m': u'6.745619', 'quoteVolume24h': u'21.43307455', 'quoteVolume8h': u'2.03708838'}, {u'USDT_XMP': {'quoteVolume60m': 0, 'last': u'27.5453345', 'close60m': 0, 'close5m': u'28.21000141', 'close30m': u'28.71000004', 'close8h': u'30.17823249', 'quoteVolume30m': u'9.98429023', 'close24h': u'34.5', 'quoteVolume': u'8667.24172620', 'quoteVolume5m': u'6.745619', 'quoteVolume24h': u'21.43307455', 'quoteVolume8h': u'2.03708838'}}
I'd like to get something like:
Index quoteVolume60m last ...
USDT_REP 0 28.21000141
USDT_XMP 0 27.5453345
I've tried:
df = pd.DataFrame.from_dict(my_dict)
But I get :
USDT_REP
close24h 34.10010003
close30m 28.99999805
close5m 28.21
close60m 0
close8h 30.17823237
Any idea how to achieve this?
Upvotes: 0
Views: 146
Reputation: 4866
The solution should be using orient
parameter in from_dict
function call.
As stated by the documentation:
orient : {‘columns’, ‘index’}, default ‘columns’
The “orientation” of the data. If the keys of the passed dict should be the columns of the resulting DataFrame, pass ‘columns’ (default). Otherwise if the keys should be rows, pass ‘index’.
So, try using:
from_dict(my_dict, orient='index')
Upvotes: 1