Python Forum
Pandas nested json data to dataframe
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?
Reply
#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).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Add NER output to pandas dataframe dg3000 0 35 11 hours ago
Last Post: dg3000
  Grouping in pandas/multi-index data frame Aleqsie 3 678 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  HTML Decoder pandas dataframe column mbrown009 3 1,047 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 1,125 Jan-06-2023, 10:53 PM
Last Post: haihal
Smile How to further boost the data read write speed using pandas tjk9501 1 1,269 Nov-14-2022, 01:46 PM
Last Post: jefsummers
  Parse Nested JSON String in Python rwalde 4 2,950 Sep-08-2022, 10:32 AM
Last Post: rwalde
  How to insert data in a dataframe? man0s 1 1,332 Apr-26-2022, 11:36 PM
Last Post: jefsummers
  Pandas Dataframe Filtering based on rows mvdlm 0 1,441 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 2,324 Mar-02-2022, 08:22 AM
Last Post: mcva
Thumbs Up can't access data from URL in pandas/jupyter notebook aaanoushka 1 1,867 Feb-13-2022, 01:19 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020