我有一个dict列表,如下所示:
[
{
'project': 'one',
'name': 'test',
'samples':
[
{'timestamp': 12, 'value': None},
{'timestamp': 23, 'value': None}
]
},
{
'project': 'two',
'name': 'best',
'samples':
[
{'timestamp': 12, 'value': None},
{'timestamp': 23, 'value': None}
]
}
]
我正在尝试构建一个数据帧,它看起来像这样:
project, name, timestamp, values
one, test, 12, none
one, test, 23, none
two, best, 12, none
two, best, 23, none
当我尝试将dict直接放入数据帧时,我会得到这样的结果:
project, name, sample
one, test, [{timestamp:12, value:none},timestamp:23, value:none}]
任何帮助都将不胜感激!
在此处检查json_normalize
,l
是您的列表
from pandas.io.json import json_normalize
json_normalize(l, 'samples', ['name', 'project',['value', 'timestamp']],errors='ignore').drop('value.timestamp',1)
Out[195]:
timestamp value project name
0 12 None one test
1 23 None one test
2 12 None two best
3 23 None two best