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
  Create dataframe from the unique data of two dataframes Calab 6 977 Mar-02-2025, 01:51 PM
Last Post: Pedroski55
Question [Solved] Formatting cells of a pandas dataframe into an OpenDocument ods spreadsheet Calab 1 674 Mar-01-2025, 04:51 AM
Last Post: Calab
  Find duplicates in a pandas dataframe list column on other rows Calab 2 2,191 Sep-18-2024, 07:38 PM
Last Post: Calab
  Find strings by index from a list of indexes in a different Pandas dataframe column Calab 3 1,630 Aug-26-2024, 04:52 PM
Last Post: Calab
  Parsing "aTimeLogger" Android app data to graphs using pandas Drone4four 8 3,263 Jun-23-2024, 07:12 AM
Last Post: Drone4four
  Add NER output to pandas dataframe dg3000 0 1,157 Apr-22-2024, 08:14 PM
Last Post: dg3000
  Grouping in pandas/multi-index data frame Aleqsie 3 2,303 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  HTML Decoder pandas dataframe column mbrown009 3 2,692 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 2,018 Jan-06-2023, 10:53 PM
Last Post: haihal
Smile How to further boost the data read write speed using pandas tjk9501 1 2,043 Nov-14-2022, 01:46 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