![](/img/trans.png)
[英]In pandas, how do I flag a row in a dataframe if a date in one field matches any date within a list of dates?
[英]How do I represent a list within a dict as a row in a Pandas dataframe?
我有一個字典列表,如下所示:
[
{
'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}
]
}
]
我正在嘗試構建一個看起來像這樣的 dataframe:
project, name, timestamp, values
one, test, 12, none
one, test, 23, none
two, best, 12, none
two, best, 23, none
當我嘗試將字典直接放入 dataframe 時,我得到如下信息:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.