You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/io.rst
+38-2
Original file line number
Diff line number
Diff line change
@@ -1648,7 +1648,7 @@ with optional parameters:
1648
1648
1649
1649
DataFrame
1650
1650
- default is ``columns``
1651
-
- allowed values are {``split``, ``records``, ``index``, ``columns``, ``values``}
1651
+
- allowed values are {``split``, ``records``, ``index``, ``columns``, ``values``, ``table``}
1652
1652
1653
1653
The format of the JSON string
1654
1654
@@ -1732,6 +1732,9 @@ values, index and columns. Name is also included for ``Series``:
1732
1732
dfjo.to_json(orient="split")
1733
1733
sjo.to_json(orient="split")
1734
1734
1735
+
**Table oriented** serializes to the JSON `Table Schema`_, allowing for the
1736
+
preservation of metadata including but not limited to dtypes and index names.
1737
+
1735
1738
.. note::
1736
1739
1737
1740
Any orient option that encodes to a JSON object will not preserve the ordering of
@@ -1848,6 +1851,7 @@ is ``None``. To explicitly force ``Series`` parsing, pass ``typ=series``
1848
1851
``values``; just the values array
1849
1852
``table``; adhering to the JSON `Table Schema`_
1850
1853
1854
+
1851
1855
- ``dtype`` : if True, infer dtypes, if a dict of column to dtype, then use those, if False, then don't infer dtypes at all, default is True, apply only to the data
1852
1856
- ``convert_axes`` : boolean, try to convert the axes to the proper dtypes, default is True
1853
1857
- ``convert_dates`` : a list of columns to parse for dates; If True, then try to parse date-like columns, default is True
@@ -2203,7 +2207,39 @@ A few notes on the generated table schema:
A ``DataFrame`` can now be written to and subsequently read back via JSON while preserving metadata through usage of the ``orient='table'`` argument (see :issue:`18912` and :issue:`9146`). Previously, none of the available ``orient`` values guaranteed the preservation of dtypes and index names, amongst other metadata.
154
154
@@ -160,35 +160,21 @@ A ``DataFrame`` can now be written to and subsequently read back via JSON while
In [17]: df.to_json("test.json", orient='columns')
169
-
In [17]: pd.read_json("test.json", orient='columns')
170
-
Out[18]:
171
-
bar baz foo qux
172
-
0 a 1514764800000 1 a
173
-
1 b 1514851200000 2 b
174
-
2 c 1514937600000 3 c
175
-
3 d 1515024000000 4 c
176
-
177
-
Current Behavior:
178
-
179
-
.. code-block:: ipython
169
+
Please note that the string `index` is not supported with the round trip format, as it is used by default in ``write_json`` to indicate a missing index name.
180
170
181
-
In [29]: df.to_json("test.json", orient='table')
182
-
In [30]: pd.read_json("test.json", orient='table')
183
-
Out[30]:
184
-
bar baz foo qux
185
-
idx
186
-
0 a 2018-01-01 1 a
187
-
1 b 2018-01-02 2 b
188
-
2 c 2018-01-03 3 c
189
-
3 d 2018-01-04 4 c
171
+
.. ipython:: python
190
172
191
-
Please note that the string `index` is not supported with the round trip format, as it is used by default in ``write_json`` to indicate a missing index name.
0 commit comments