Trying to figure out how to write json to pandas DataFrame. In code I have:
...
resp = s.get(URL)
df = pd.DataFrame.from_dict(resp.json())
print(df.to_string())
My response in json looks like this:
{
"instrument": "EUR_USD",
"granularity": "S5",
"candles": [
{
"complete": true,
"volume": 8,
"time": "2020-02-28T17:22:55.000000000Z",
"mid": {
"o": "1.10087",
"h": "1.10088",
"l": "1.10083",
"c": "1.10083"
}
},
{
"complete": false,
"volume": 7,
"time": "2020-02-28T17:23:00.000000000Z",
"mid": {
"o": "1.10084",
"h": "1.10084",
"l": "1.10078",
"c": "1.10078"
}
}
]
}
If I print df, I get this:
instrument granularity candles
0 EUR_USD S5 {'complete': True, 'volume': 17, 'time': '2020-02-28T17:26:55.000000000Z', 'mid': {'o': '1.10022', 'h': '1.10023', 'l': '1.10014', 'c': '1.10014'}}
1 EUR_USD S5 {'complete': False, 'volume': 19, 'time': '2020-02-28T17:27:00.000000000Z', 'mid': {'o': '1.10012', 'h': '1.10024', 'l': '1.10012', 'c': '1.10024'}}
How can I manipulate writing json to pandas df, so that my df would look like:
time open high low close volume
2020-02-28T17:26:55.000000000Z 1.10022 1.10023 1.10014 1.10014 17
...