-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Expand on reference docs for read_json #14442
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
Changes from 3 commits
94fc456
943baee
bdc25b7
32c045c
5e34a02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,32 +123,38 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True, | |
file. For file URLs, a host is expected. For instance, a local file | ||
could be ``file://localhost/path/to/table.json`` | ||
|
||
orient | ||
orient : string, | ||
Indication of expected JSON string format. | ||
Compatible JSON strings can be produced by ``to_json()`` with a | ||
corresponding orient value. | ||
The set of possible orients is: | ||
|
||
* `Series` | ||
- ``'split'`` : dict like | ||
``{index -> [index], columns -> [columns], data -> [values]}`` | ||
- ``'records'`` : list like | ||
``[{column -> value}, ... , {column -> value}]`` | ||
- ``'index'`` : dict like ``{index -> {column -> value}}`` | ||
- ``'columns'`` : dict like ``{column -> {index -> value}}`` | ||
- ``'values'`` : just the values array | ||
|
||
The allowed and default values depend on the value | ||
of the `typ` parameter. | ||
|
||
* when ``typ == 'series'``, | ||
|
||
- allowed orients are ``{'split','records','index'}`` | ||
- default is ``'index'`` | ||
- allowed values are: ``{'split','records','index'}`` | ||
- The Series index must be unique for orient ``'index'``. | ||
|
||
* `DataFrame` | ||
* when ``typ == 'frame'``, | ||
|
||
- allowed orients are ``{'split','records','index', | ||
'columns','values'}`` | ||
- default is ``'columns'`` | ||
- allowed values are: {'split','records','index','columns','values'} | ||
- The DataFrame index must be unique for orients 'index' and | ||
'columns'. | ||
- The DataFrame columns must be unique for orients 'index', | ||
'columns', and 'records'. | ||
|
||
* The format of the JSON string | ||
|
||
- split : dict like | ||
``{index -> [index], columns -> [columns], data -> [values]}`` | ||
- records : list like | ||
``[{column -> value}, ... , {column -> value}]`` | ||
- index : dict like ``{index -> {column -> value}}`` | ||
- columns : dict like ``{column -> {index -> value}}`` | ||
- values : just the values array | ||
- The DataFrame index must be unique for orients ``'index'`` and | ||
``'columns'``. | ||
- The DataFrame columns must be unique for orients ``'index'``, | ||
``'columns'``, and ``'records'``. | ||
|
||
typ : type of object to recover (series or frame), default 'frame' | ||
dtype : boolean or dict, default True | ||
|
@@ -197,7 +203,44 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True, | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a See Also section and reference read_json (and vice versa there) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback This is the docstring of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, meant |
||
Returns | ||
------- | ||
result : Series or DataFrame | ||
result : Series or DataFrame, depending on the value of `typ`. | ||
|
||
Examples | ||
-------- | ||
|
||
>>> df = pd.DataFrame([['a', 'b'], ['c', 'd']], | ||
... index=['row 1', 'row 2'], | ||
... columns=['col 1', 'col 2']) | ||
|
||
Encoding/decoding a Dataframe using ``'split'`` formatted JSON: | ||
|
||
>>> df.to_json(orient='split') | ||
'{"columns":["col 1","col 2"], | ||
"index":["row 1","row 2"], | ||
"data":[["a","b"],["c","d"]]}' | ||
>>> pd.read_json(_, orient='split') | ||
col 1 col 2 | ||
row 1 a b | ||
row 2 c d | ||
|
||
Encoding/decoding a Dataframe using ``'index'`` formatted JSON: | ||
|
||
>>> df.to_json(orient='index') | ||
'{"row 1":{"col 1":"a","col 2":"b"},"row 2":{"col 1":"c","col 2":"d"}}' | ||
>>> pd.read_json(_, orient='index') | ||
col 1 col 2 | ||
row 1 a b | ||
row 2 c d | ||
|
||
Encoding/decoding a Dataframe using ``'records'`` formatted JSON. | ||
Note that index labels are not preserved with this encoding. | ||
|
||
>>> df.to_json(orient='records') | ||
'[{"col 1":"a","col 2":"b"},{"col 1":"c","col 2":"d"}]' | ||
>>> pd.read_json(_, orient='records') | ||
col 1 col 2 | ||
0 a b | ||
1 c d | ||
""" | ||
|
||
filepath_or_buffer, _, _ = get_filepath_or_buffer(path_or_buf, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some indentation here compared to the base level of "The set of ..." (which is not needed)