Python Forum

Full Version: Pandas nested json data to dataframe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
We have this json response:
https://api.binance.com/api/v1/exchangeInfo

And want to get each symbol filters content in a dataframe.

How can we do it?
To interpret the json-data as a DataFrame object Pandas requires the same length
of all entries. So, pd.read_json(...) will fail to convert data to a valid DataFrame.
However, you can load it as a Series, e.g.

import pandas as pd
data = pd.read_json('https://api.binance.com/api/v1/exchangeInfo', typ='series')
From now, you can follow different ways to interpret the data as a DataFrame object: use Pandas MultiIndex and build a panel data structure, or build a DataFrame object directly, e.g.

my_df = pd.concat([pd.DataFrame(data.symbols[j]['filters']).assign(symbol_id=j) for j in range(len(data.symbols))]).reset_index()
Note, in this code I used assign method to store symbol ids (it might be useful for future analysis).