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')
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
180
+
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
190
+
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.
192
+
148
193
.. _whatsnew_0230.enhancements.other:
149
194
150
195
Other Enhancements
@@ -171,7 +216,6 @@ Other Enhancements
171
216
- ``Resampler`` objects now have a functioning :attr:`~pandas.core.resample.Resampler.pipe` method.
172
217
Previously, calls to ``pipe`` were diverted to the ``mean`` method (:issue:`17905`).
173
218
- :func:`~pandas.api.types.is_scalar` now returns ``True`` for ``DateOffset`` objects (:issue:`18943`).
174
-
- :func:`read_json` now supports ``table`` as a value to the ``orient`` argument (:issue:`18912`)
0 commit comments