Skip to content

New orientation for to_json method #5729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
julius-datajunkie opened this issue Dec 18, 2013 · 3 comments
Closed

New orientation for to_json method #5729

julius-datajunkie opened this issue Dec 18, 2013 · 3 comments
Labels
Duplicate Report Duplicate issue or pull request Enhancement IO JSON read_json, to_json, json_normalize

Comments

@julius-datajunkie
Copy link

start = datetime.datetime(2013, 1, 1)
end = datetime.datetime(2013, 01, 27)
f=web.get_data_yahoo('AAPL',start, end)
f['Adj Close'].to_json(date_format='iso',orient='split')

The above code gives the following result:

'{"name":"Adj Close","index":["2013-01-02T00:00:00","2013-01-03T00:00:0
0","2013-01-04T00:00:00","2013-01-07T00:00:00","2013-01-08T00:00:00","2013-01-09
T00:00:00","2013-01-10T00:00:00","2013-01-11T00:00:00","2013-01-14T00:00:00","20
13-01-15T00:00:00","2013-01-16T00:00:00","2013-01-17T00:00:00","2013-01-18T00:00
:00","2013-01-22T00:00:00","2013-01-23T00:00:00","2013-01-24T00:00:00","2013-01-
25T00:00:00"],"data":[535.58,528.82,514.09,511.06,512.44,504.43,510.68,507.55,48
9.45,474.01,493.69,490.36,487.75,492.4,501.41,439.46,429.1]}'

What I want is:

'[{"index":"2013-01-02T00:00:00",value:535.58},{"index":"2013-01-04T00:00:00",value:528.82},...]'

This is useful when using D3JS, and potentially many more places.

@jreback
Copy link
Contributor

jreback commented Dec 18, 2013

cc @Komnomnomnom

way to do this currently?

@Komnomnomnom
Copy link
Contributor

@zsljulius you could do something like this curently

In [26]: f['date'] = f.index

In [27]: f.loc[:, ['date', 'Adj Close']].to_json(date_format='iso', orient='records')
Out[27]: '[{"date":"2013-01-02T00:00:00.000Z","Adj Close":535.58},{"date":"2013-01-03T00:00:00.000Z","Adj Close":528.82},{"date":"2013-01-04T00:00:00.000Z","Adj Close":514.09},{"date":"2013-01-07T00:00:00.000Z","Adj Close":511.06},{"date":"2013-01-08T00:00:00.000Z","Adj Close":512.44},{"date":"2013-01-09T00:00:00.000Z","Adj Close":504.43},{"date":"2013-01-10T00:00:00.000Z","Adj Close":510.68},{"date":"2013-01-11T00:00:00.000Z","Adj Close":507.55},{"date":"2013-01-14T00:00:00.000Z","Adj Close":489.45},{"date":"2013-01-15T00:00:00.000Z","Adj Close":474.01},{"date":"2013-01-16T00:00:00.000Z","Adj Close":493.69},{"date":"2013-01-17T00:00:00.000Z","Adj Close":490.36},{"date":"2013-01-18T00:00:00.000Z","Adj Close":487.75},{"date":"2013-01-22T00:00:00.000Z","Adj Close":492.4},{"date":"2013-01-23T00:00:00.000Z","Adj Close":501.41},{"date":"2013-01-24T00:00:00.000Z","Adj Close":439.46},{"date":"2013-01-25T00:00:00.000Z","Adj Close":429.1}]'

It would probably be nice to either include the index in the records orient, or to have a flag to do so. Any opinions on this?

@jreback
Copy link
Contributor

jreback commented Sep 18, 2017

closing as dupe of #17394

@jreback jreback closed this as completed Sep 18, 2017
@jorisvandenbossche jorisvandenbossche modified the milestones: Next Major Release, No action Sep 18, 2017
@jorisvandenbossche jorisvandenbossche added the Duplicate Report Duplicate issue or pull request label Sep 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Enhancement IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

No branches or pull requests

4 participants