Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Pandas nested json data to dataframe
#1
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?
Quote
#2
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).
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  error bars with dataframe and pandas Hucky 4 279 Apr-27-2020, 02:02 AM
Last Post: Hucky
  Read json array data by pandas vipinct 0 143 Apr-13-2020, 02:24 PM
Last Post: vipinct
  Python Pandas DataFrame Help AmericanEagle1989 1 181 Apr-12-2020, 12:37 PM
Last Post: AmericanEagle1989
  How does pyplot know what was plotted by the output of pandas.DataFrame(...).cumprod( codeowl 2 194 Mar-28-2020, 08:27 AM
Last Post: j.crater
  add formatted column to pandas data frame alkaline3 0 171 Mar-22-2020, 06:44 PM
Last Post: alkaline3
  Ordering of pandas DataFrame new_to_python 5 270 Mar-15-2020, 06:08 PM
Last Post: new_to_python
  Pandas dataframe merge snmmat 1 257 Mar-09-2020, 06:56 PM
Last Post: jefsummers
  Transform Facebook Graph API insights JSON to pandas dataframe usman 0 274 Mar-03-2020, 05:14 AM
Last Post: usman
  JSON to Dataframe DrX 1 253 Feb-19-2020, 07:58 PM
Last Post: DrX
  Obtaining Correct Date In Pandas DataFrame eddywinch82 14 1,392 Feb-17-2020, 11:45 AM
Last Post: eddywinch82

Forum Jump:


Users browsing this thread: 1 Guest(s)