【发布时间】:2020-06-25 08:15:03
【问题描述】:
我是 python 世界的新手。我正在通过 API 获取下面的 JSON,我想处理并将其转换为数据框。
{
"events": [
{
"labels": [],
"links": [
{
"href": "https://context/323472912?per_page=50×tamp=1590989425549&log_keys=",
"rel": "Context"
}
],
"log_id": "471a-berwf-a899wrcf",
"message": "gwex [2020-06-01 05:30:20.260] WARN [2344423424234] [Utils] [CFA] User not available, name: George, department: sales, id: 001",
"timestamp": 1590989425549
},
{
"labels": [],
"links": [
{
"href": "https://context/3235933?per_page=50×tamp=1590989425618&log_keys=",
"rel": "Context"
}
],
"log_id": "039-ad2a-be3f-a84b9cf",
"message": "gwex [2020-06-01 05:30:21.275] WARN [234478424234] [2344423424234] [Utils] [CFA] User not available, name: Mark, department: marketing, id: 002",
"timestamp": 1590989425618
},
],
"leql": {
"during": {
},
"statement":
},
}
data = eval(jsonresp.text)
df = pd.DataFrame.from_dict(json_normalize(data), orient='columns')
上述查询提供的列是事件、leql.during、leql.statement、链接。 “事件”标签中的所有数据都填充在一列中,使其不可读。
我想要一个 CSV 文件,它只包含事件标签中的数据,并将 log_id、消息、时间戳作为单独的列。
【问题讨论】: