我尝试阅读get a nested mongodb result into a pandas dataframe。
数据看起来像这样。
{
"_id" : ObjectId("5911b9cebb56c016794d45a4"),
"crawlat" : "2017-05-09 14:45",
"traffic" : [
{
"timestamp" : "1494338401",
"organic" : 53
},
{
"timestamp" : "1494342001",
"organic" : 64
},
{
"timestamp" : "1494345601",
"organic" : 74
},
{
"timestamp" : "1494349201",
"organic" : 78
},
{
"timestamp" : "1494352801",
"organic" : 80
},
{
"timestamp" : "1494356401",
"organic" : 88
},
{
"timestamp" : "1494360001",
"organic" : 91
},
{
"timestamp" : "1494363601",
"organic" : 92
},
{
"timestamp" : "1494367201",
"organic" : 94
}
]
}
traffic数组包含每个结果的48个条目。
我只对按数组顺序排列的“有机”值感兴趣。
我从
^{pr2}$我用json规范化和
dfsitemap = dfsitemap['traffic'].apply(pd.Series)
结果是这样的
但我需要一张只有有机值的表格。我该怎么清理这个?
您可以使用
from_records
构造函数创建数据帧,该构造函数允许您指定要包含或排除的列:它给出了:
相关问题 更多 >
编程相关推荐