Pandas nested json data to dataframe - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Pandas nested json data to dataframe (/thread-12183.html) |
Pandas nested json data to dataframe - FrankC - Aug-13-2018 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? RE: Pandas nested json data to dataframe - scidam - Aug-14-2018 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).
|