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
ENH: added convert_axes argument to control whether to coerce axes
ENH: changed dtype argument to accept a dict for a per-column dtype conversion, or
turn off conversion (default is True)
ENH: changed parse_dates to convert_dates, now defaulting to True
BUG: not processing correctly some parsable JSON
Copy file name to clipboardExpand all lines: doc/source/io.rst
+51-5
Original file line number
Diff line number
Diff line change
@@ -989,6 +989,8 @@ Writing to a file, with a date index and a date column
989
989
990
990
dfj2 = dfj.copy()
991
991
dfj2['date'] = Timestamp('20130101')
992
+
dfj2['ints'] =range(5)
993
+
dfj2['bools'] =True
992
994
dfj2.index = date_range('20130101',periods=5)
993
995
dfj2.to_json('test.json')
994
996
open('test.json').read()
@@ -1011,25 +1013,69 @@ is ``None``. To explicity force ``Series`` parsing, pass ``typ=series``
1011
1013
* records : list like [value, ... , value]
1012
1014
* index : dict like {index -> value}
1013
1015
1014
-
- dtype : dtype of the resulting object
1015
-
- numpy : direct decoding to numpy arrays. default True but falls back to standard decoding if a problem occurs.
1016
-
- parse_dates : a list of columns to parse for dates; If True, then try to parse datelike columns, default is False
1016
+
- 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
1017
+
- convert_axes : boolean, try to convert the axes to the proper dtypes, default is True
1018
+
- convert_dates : a list of columns to parse for dates; If True, then try to parse datelike columns, default is True
1017
1019
- keep_default_dates : boolean, default True. If parsing dates, then parse the default datelike columns
1020
+
- numpy: direct decoding to numpy arrays. default True but falls back to standard decoding if a problem occurs.
1018
1021
1019
1022
The parser will raise one of ``ValueError/TypeError/AssertionError`` if the JSON is
1020
1023
not parsable.
1021
1024
1025
+
The default of ``convert_axes=True``, ``dtype=True``, and ``convert_dates=True`` will try to parse the axes, and all of the data
1026
+
into appropriate types, including dates. If you need to override specific dtypes, pass a dict to ``dtype``. ``convert_axes`` should only
1027
+
be set to ``False`` if you need to preserve string-like numbers (e.g. '1', '2') in an axes.
1028
+
1029
+
.. warning::
1030
+
1031
+
When reading JSON data, automatic coercing into dtypes has some quirks:
1032
+
1033
+
* an index can be in a different order, that is the returned order is not guaranteed to be the same as before serialization
1034
+
* a column that was ``float`` data can safely be converted to ``integer``, e.g. a column of ``1.``
1035
+
* bool columns will be converted to ``integer`` on reconstruction
1036
+
1037
+
Thus there are times where you may want to specify specific dtypes via the ``dtype`` keyword argument.
1038
+
1022
1039
Reading from a JSON string
1023
1040
1024
1041
.. ipython:: python
1025
1042
1026
1043
pd.read_json(json)
1027
1044
1028
-
Reading from a file, parsing dates
1045
+
Reading from a file
1046
+
1047
+
.. ipython:: python
1048
+
1049
+
pd.read_json('test.json')
1050
+
1051
+
Don't convert any data (but still convert axes and dates)
0 commit comments