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
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.
In [17]: df.to_json("test.json", orient='columns')
143
+
In [17]: pd.read_json("test.json", orient='columns')
144
+
Out[18]:
145
+
bar baz foo qux
146
+
0 a 1514764800000 1 a
147
+
1 b 1514851200000 2 b
148
+
2 c 1514937600000 3 c
149
+
3 d 1515024000000 4 c
150
+
151
+
Current Behavior:
152
+
153
+
.. code-block:: ipython
154
+
155
+
In [29]: df.to_json("test.json", orient='table')
156
+
In [30]: pd.read_json("test.json", orient='table')
157
+
Out[30]:
158
+
bar baz foo qux
159
+
idx
160
+
0 a 2018-01-01 1 a
161
+
1 b 2018-01-02 2 b
162
+
2 c 2018-01-03 3 c
163
+
3 d 2018-01-04 4 c
164
+
165
+
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.
166
+
122
167
.. _whatsnew_0230.enhancements.other:
123
168
124
169
Other Enhancements
@@ -145,7 +190,6 @@ Other Enhancements
145
190
- ``Resampler`` objects now have a functioning :attr:`~pandas.core.resample.Resampler.pipe` method.
146
191
Previously, calls to ``pipe`` were diverted to the ``mean`` method (:issue:`17905`).
147
192
- :func:`~pandas.api.types.is_scalar` now returns ``True`` for ``DateOffset`` objects (:issue:`18943`).
148
-
- :func:`read_json` now supports ``table`` as a value to the ``orient`` argument (:issue:`18912`)
0 commit comments