Мне нужно создать фрейм данных pandas из списка вложенных словарей. Ниже мой словарь:
[
{
"id": "e182_1234",
"stderr": {
"type": "stderr",
"upload time": "Thu Jun 25 12:24:52 +0100 2020",
"length": 3000,
"contents": [
{
"date": "20/06/25",
"time": "12:19:39",
"type": "ERROR",
"text": "Exception found\njava.io.Exception:Not initated\n at.apache.java.org........",
"line_start": 12,
"line_end": 15
},
{
"date": "20/06/25",
"time": "12:20:41",
"type": "WARN",
"text": "Warning as the node is accessed without started",
"line_start": 17,
"line_end": 17
}
]
}
}
]
Я попытался создать фрейм данных, используя приведенный ниже код:
df=pd.DataFrame(filtered_data) #filtered_data is the above dictionary
res1=df.join(pd.DataFrame(df.pop("stderr").tolist()))
res2=res1.join(pd.DataFrame(res1.pop("contents").tolist()))
Результат, который я получил:
#df=pd.DataFrame(filtered_data)
id stderr
0 e182_1234 {'type': 'stderr', 'upload time': 'Thu Jun 25 ...
#res1=df.join(pd.DataFrame(df.pop("stderr").tolist()))
id type upload time length contents
0 e182_1234 stderr Thu Jun 25 12:24:52 +0100 2020 3000 [{'date': '20/06/25', 'time': '12:19:39', 'typ...
#res2=res1.join(pd.DataFrame(res1.pop("contents").tolist()))
id type upload time length 0 1
0 e182_1234 stderr Thu Jun 25 12:24:52 +0100 2020 3000 {'date': '20/06/25', 'time': '12:19:39', 'type... {'date': '20/06/25', 'time': '12:20:41', 'type...
Как вы можете, когда я разделил список каталогов, он получил имя столбца 0
и 1
. Я хочу, чтобы эти столбцы были разделены, как date,time,type,text,line_start,line_end
, отдельными столбцами.
Ожидаемый результат:
id type upload time length date time type text line_start line_end
0 e182_1234 stderr Thu Jun 25 12:24:52 +0100 2020 3000 20/06/25 12:19:39 ERROR Exception found\njava.io.Exception:Not initated\n at.apache.java.org........ 12 15
1 e182_1234 stderr Thu Jun 25 12:24:52 +0100 2020 3000 20/06/25 12:20:41 WARN WARN Warning as the node is accessed without started 17 17
Как отсортировать эту проблему? Заранее спасибо!