I have a JSON file called "values.json" with this content:
{
"values": [{
"id": 2,
"value": "passed"
}, {
"id": 41,
"value": "passed"
}, {
"id": 73,
"value": "passed"
}, {
"id": 110,
"value": "failed"
}, {
"id": 122,
"value": "failed"
}, {
"id": 234,
"value": "passed"
}, {
"id": 238,
"value": "passed"
}, {
"id": 345,
"value": "passed"
}, {
"id": 653,
"value": "passed"
}, {
"id": 690,
"value": "failed"
}, {
"id": 5321,
"value": "passed"
}, {
"id": 5322,
"value": "failed"
}]
}
I try to convert it to dataframe with next code:
values_path = "values.json"
df = pd.read_json(values_path)
with open(values_path) as f:
d = json.load(f)
df = pd.json_normalize(d)
print(df)
However, I get the table with one column and one row:
values
0 [{'id': 2, 'value': 'passed'}, {'id': 41, 'val...
My desired output would be something like that:
id | value | |
---|---|---|
0 | 2 | passed |
1 | 41 | passed |
2 | 73 | passed |
What do I do wrong? Or maybe there is something wrong with my JSON file? I will be thankful for any help!
3
Answers
The data you want is inside the
values
key, so you just need to select it: