Я могу прочитать файл json и преобразовать его в фрейм данных, используя приведенный ниже код.
df = open(jsontable, "normal.json") |> DataFrame
normal.json
выглядит, как показано ниже,
{"col1" : ["тасин", "привет", "мир"], "col2": [1,2,3], "col3": ["ab c", "def", "ghi"]}
Итак, final df имеет,
3×3 DataFrame
│ Row │ col1 │ col2 │ col3 │
│ │ String │ Int64 │ String │
├─────┼────────┼───────┼────────┤
│ 1 │ thasin │ 1 │ abc │
│ 2 │ hello │ 2 │ def │
│ 3 │ world │ 3 │ ghi │
Но тот же код не работает для record
отформатированного json файла.
формат как список {столбец -> значение},…, {столбец -> значение}
Мой образец json
{"billing_account_id":"0139A","credits":[],"invoice":{"month":"202003"},"cost_type":"regular"}
{"billing_account_id":"0139A","credits":[1.45],"invoice":{"month":"202003"},"cost_type":"regular"}
{"billing_account_id":"0139A","credits":[2.00, 3.56],"invoice":{"month":"202003"},"cost_type":"regular"}
Ожидаемый результат:
billing_account_id cost_type credits invoice
0 0139A regular [] {'month': '202003'}
1 0139A regular [1.45] {'month': '202003'}
2 0139A regular [2.0, 3.56] {'month': '202003'}
Это может быть сделано в python, как показано ниже,
data = []
for line in open("sample.json", 'r'):
data.append(json.loads(line))
print(data)
df=pd.DataFrame(data)
Как это сделать в Юлии?