熊猫:创建多层表或子表格
我在列表中具有字典格式的数据:
data_dict = [{
"exchange": "binance",
"base": "kp3r",
"quote": "busd",
"resolution": 15,
"ohlcv": [
{
"source_id": 7905,
"timestamp": "2022-07-05T14:45:00.000Z",
"open": "131.55",
"high": "131.84",
"low": "130.38",
"close": "130.94",
"volume": "90.29"
},
{
"source_id": 7905,
"timestamp": "2022-07-05T14:45:00.000Z",
"open": "131.55",
"high": "131.84",
"low": "130.38",
"close": "130.94",
"volume": "90.29"
},
{
"source_id": 19252,
"timestamp": "2022-07-05T13:00:00.000Z",
"open": "24.5610000000000000",
"high": "24.5610000000000000",
"low": "24.5610000000000000",
"close": "24.5610000000000000",
"volume": "0.0000000000000000"
}]
},
{
"exchange": "kucoin",
"base": "mln",
"quote": "usdt",
"resolution": 15,
"ohlcv": [
{
"source_id": 19252,
"timestamp": "2022-07-05T13:00:00.000Z",
"open": "24.56",
"high": "24.56",
"low": "24.56",
"close": "24.56",
"volume": "0.0"
}]
}
]
现在我需要表格像( greenge ):
exchange base ... resolution source_id timestamp open high low close volume
0 binance kp3r ... 15 7905 2022-07-05T14:45:00.000Z 131.55 131.84 130.38 130.94 90.29
7905 2022-07-05T14:45:00.000Z 131.55 131.84 130.38 130.94 90.29
19252 2022-07-05T13:00:00.000Z 24.56 24.56 24.56 24.56 0.0
1 kucoin mln ... 15 19252 2022-07-05T13:00:00.000Z 24.56 24.56 24.56 24.56 0.0
这是我尝试的:
pd.DataFrame.from_dict(data_dict)
它给了我
exchange base ... resolution ohlcv
0 binance kp3r ... 15 [{'source_id': 7905, 'timestamp': '2022-07-05T...
1 kucoin mln ... 15 [{'source_id': 19252, 'timestamp': '2022-07-05...
I have data in dictionary format in a list as :
data_dict = [{
"exchange": "binance",
"base": "kp3r",
"quote": "busd",
"resolution": 15,
"ohlcv": [
{
"source_id": 7905,
"timestamp": "2022-07-05T14:45:00.000Z",
"open": "131.55",
"high": "131.84",
"low": "130.38",
"close": "130.94",
"volume": "90.29"
},
{
"source_id": 7905,
"timestamp": "2022-07-05T14:45:00.000Z",
"open": "131.55",
"high": "131.84",
"low": "130.38",
"close": "130.94",
"volume": "90.29"
},
{
"source_id": 19252,
"timestamp": "2022-07-05T13:00:00.000Z",
"open": "24.5610000000000000",
"high": "24.5610000000000000",
"low": "24.5610000000000000",
"close": "24.5610000000000000",
"volume": "0.0000000000000000"
}]
},
{
"exchange": "kucoin",
"base": "mln",
"quote": "usdt",
"resolution": 15,
"ohlcv": [
{
"source_id": 19252,
"timestamp": "2022-07-05T13:00:00.000Z",
"open": "24.56",
"high": "24.56",
"low": "24.56",
"close": "24.56",
"volume": "0.0"
}]
}
]
Now I need the table to be something like (Expected) :
exchange base ... resolution source_id timestamp open high low close volume
0 binance kp3r ... 15 7905 2022-07-05T14:45:00.000Z 131.55 131.84 130.38 130.94 90.29
7905 2022-07-05T14:45:00.000Z 131.55 131.84 130.38 130.94 90.29
19252 2022-07-05T13:00:00.000Z 24.56 24.56 24.56 24.56 0.0
1 kucoin mln ... 15 19252 2022-07-05T13:00:00.000Z 24.56 24.56 24.56 24.56 0.0
This is what I have tried :
pd.DataFrame.from_dict(data_dict)
which gives me
exchange base ... resolution ohlcv
0 binance kp3r ... 15 [{'source_id': 7905, 'timestamp': '2022-07-05T...
1 kucoin mln ... 15 [{'source_id': 19252, 'timestamp': '2022-07-05...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
打印:
Try:
Prints: