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 [5]: new_df = pd.read_json('test.json', orient='table')
32
+
df = pd.DataFrame({'A': [1, 2, 3]})
33
+
df
34
+
df.assign(B=df.A, C=lambdax: x['A'] + x['B'])
83
35
84
-
In [6]: new_df
85
-
Out[6]:
86
-
foo bar baz qux
87
-
idx
88
-
0 1 a 2018-01-01 a
89
-
1 2 b 2018-01-02 b
90
-
2 3 c 2018-01-03 c
91
-
3 4 d 2018-01-04 c
36
+
.. ipython:: python
92
37
93
-
[4 rows x 4 columns]
38
+
df.assign(A=df.A +1, C=lambdadf: df.A *-1)
94
39
95
-
In [7]: new_df.dtypes
96
-
Out[7]:
97
-
foo int64
98
-
bar object
99
-
baz datetime64[ns]
100
-
qux category
101
-
Length: 4, dtype: object
40
+
.. ipython:: python
102
41
103
-
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