我有一个嵌套列表的字典
d = {'IBGB100': [RealTimeBar(time=datetime.datetime(2019, 2, 21, 19, 17, tzinfo=datetime.timezone.utc), open_=7169.42, high=7169.67, low=7169.42, close=7169.42, volume=-1, wap=-1.0, count=-1),
RealTimeBar(time=datetime.datetime(2019, 2, 21, 19, 17, 5, tzinfo=datetime.timezone.utc), open_=7169.42, high=7169.42, low=7168.92, close=7168.92, volume=-1, wap=-1.0, count=-1)],
'IBEU50': [RealTimeBar(time=datetime.datetime(2019, 2, 21, 19, 17, tzinfo=datetime.timezone.utc), open_=3262.455, high=3262.455, low=3262.455, close=3262.455, volume=-1, wap=-1.0, count=-1),
RealTimeBar(time=datetime.datetime(2019, 2, 21, 19, 17, 5, tzinfo=datetime.timezone.utc), open_=3262.455, high=3262.455, low=3262.455, close=3262.455, volume=-1, wap=-1.0, count=-1)],
'IBDE30': [RealTimeBar(time=datetime.datetime(2019, 2, 21, 19, 17, tzinfo=datetime.timezone.utc), open_=11417.15, high=11417.655, low=11416.9, close=11416.9, volume=-1, wap=-1.0, count=-1),
RealTimeBar(time=datetime.datetime(2019, 2, 21, 19, 17, 5, tzinfo=datetime.timezone.utc), open_=11416.9, high=11416.905, low=11416.15, close=11416.65, volume=-1, wap=-1.0, count=-1)]}
我正在尝试将这种格式转换为DataFrame
instrument datetime open high low close volume wap count
'IBGB100' 2019, 2, 21, 19, 17, 7169.42 7169.67 7169.42 7169.42 -1 -1.0 -1
2019, 2, 21, 19, 17, 5, 7169.42 7169.42 7168.92 7168.92 -1 -1.0 -1
'IBEU50' 2019, 2, 21, 19, 17, 3262.455 3262.455 3262.455 3262.455 -1 -1.0 -1
2019, 2, 21, 19, 17, 5, 3262.455 3262.455 3262.455 3262.455 -1 -1.0 -1
'IBDE30' 2019, 2, 21, 19, 17, 11417.15 11417.655 11416.9 11416.9 -1 -1.0 -1
2019, 2, 21, 19, 17, 5, 11416.9 11416.905 11416.15 11416.65 -1 -1.0 -1
pd.DataFrame(d).transpose()使我接近,但是我无法解决如何以列的形式访问嵌套列表数据。
嵌套列表以1xN个形状(即按列扩展)返回,而不是我需要的Nx8个形状(即按行向下扩展)返回。
0 1
'IBGB100' RealTimeBar(...) RealTimeBar(...)
'IBEU50' RealTimeBar(...) RealTimeBar(...)
'IBDE30' RealTimeBar(...) RealTimeBar(...)