Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas question
#1
Pulling from polygon.io API.
(JSON Object Response example at bottom)
green text is where im stuck
red text is from documentation
this response object from the api has no top-level key for the json.
Read https://medium.com/swlh/converting-neste...106c59976e
2/3 down they have a json_normalize example
it uses a top-level key and the response object I am getting does not have one.
what do i put in my highlighted line below?

from documentation:
pandas.json_normalize(data, record_path=None, meta=None, meta_prefix=None, record_prefix=None, errors='raise', sep='.', max_level=None)
See my work right below minus API information etc(results is the information from the API's GET request:

results = requests.get(url).json()
df = pd.DataFrame.from_records(results,columns=['symbol','isUTC','day','open','close','openTrades','closingTrades'])
FIELDS = ["symbol", "isUTC", "day", "open", "openTrades.s",'openTrades.p','openTrades.x','openTrades.t','openTrades.c','closingTrades.s','closingTrades.p','closingTrades.x','closingTrades.t','closingTrades.c']
df = pd.json_normalize(results)
df[FIELDS]
Output:
{ "symbol": "BTC-USD", "isUTC": true, "day": "2020-10-14", "open": 11442.72553612, "close": 11417.8, "openTrades": [ { "s": 0.00942955, "p": 11442.72553612, "x": 2, "t": 1602633600081, "c": [ 2 ] }, { "s": 0.00118, "p": 11443, "x": 2, "t": 1602633600338, "c": [ 2 ] }, { "s": 0.00145141, "p": 11428.22, "x": 1, "t": 1602633600593, "c": [ 1 ] }, { "s": 0.01813, "p": 11420.57, "x": 4, "t": 1602633600777, "c": [ 1 ] }, { "s": 0.002402, "p": 11420.97, "x": 4, "t": 1602633601102, "c": [ 1 ] } ], "closingTrades": [ { "s": 0.00200489, "p": 11417.8, "x": 17, "t": 1602719999943, "c": [ 2 ] }, { "s": 0.329184, "p": 11417.89, "x": 4, "t": 1602719999802, "c": [ 2 ] }, { "s": 0.002726, "p": 11417.89, "x": 4, "t": 1602719999549, "c": [ 2 ] }, { "s": 0.2, "p": 11417.89, "x": 4, "t": 1602719999512, "c": [ 2 ] }, { "s": 0.00278713, "p": 11427.7, "x": 1, "t": 1602719999498, "c": [ 1 ] } ] }
buran write Jan-10-2021, 06:54 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pandas df inside a df question mbaker_wv 4 1,184 Dec-25-2022, 01:11 AM
Last Post: mbaker_wv
  Pandas usecols question rsearing 1 1,241 Aug-20-2022, 10:10 PM
Last Post: jefsummers
  Simple pandas question mcva 4 2,646 Dec-17-2021, 04:47 PM
Last Post: mcva
  Pandas merge question smw10c 2 5,715 Jul-02-2020, 06:56 PM
Last Post: hussainmujtaba
  Counting Criteria in Pandas Question Koenig 1 2,157 Sep-30-2019, 05:16 AM
Last Post: perfringo
  Function question using Pandas smw10c 7 7,077 Feb-12-2019, 06:52 PM
Last Post: Nathandsn
  Simple pandas dataframe question popohoma 1 3,540 Jan-03-2019, 05:00 PM
Last Post: ashlardev
  question on pandas datareader kit12_31 3 9,214 Feb-05-2018, 11:55 PM
Last Post: snippsat
  Newbie question on how to use pandas.rolling_mean zydjohn 5 14,244 Dec-09-2017, 08:42 PM
Last Post: j.crater
  Pandas question takaa 3 3,816 Dec-05-2017, 01:03 PM
Last Post: takaa

Forum Jump:

User Panel Messages

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