【发布时间】:2022-01-03 01:48:56
【问题描述】:
我正在尝试从 mongodb 集合生成一个新的数据框,目标是创建一个仅代表“事件”列的新 df:
例如:
{
"_id" : 1641008579,
"status" : "init",
"description" : "Test",
"attachment" : null,
"start" : "08:00",
"user" : "Jenny",
"timestamp" : ISODate("2022-01-01T04:43:11.380Z"),
"events" : [
{
"id" : 1641008580,
"status" : "start",
"description" : "First Event",
"user" : "Jenny",
"timestamp" : ISODate("2022-01-01T04:43:11.380Z")
},
{
"id" : 1641008581,
"status" : "progress",
"description" : "Middle of the Event",
"user" : "Joe",
"timestamp" : ISODate("2022-01-01T05:43:11.380Z")
},
{
"id" : 1641008582,
"status" : "end",
"description" : "Last Event",
"user" : "Alain",
"timestamp" : ISODate("2022-01-01T06:43:11.380Z")
}
]
}
知道如何开始一种方法以获得以下结果吗?
event_df 应该如下所示:
id status description user timestamp
0 1641008580 start First Event Jenny "2022-01-01T04:43:11.380Z"
1 1641008581 progress Middle of the Event Joe "2022-01-01T05:43:11.380Z"
2 1641008582 end Last Event Alain "2022-01-01T06:43:11.380Z"
/K
【问题讨论】:
标签: python arrays mongodb dataframe nested