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
+80-15
Original file line number
Diff line number
Diff line change
@@ -954,13 +954,21 @@ with optional parameters:
954
954
955
955
- path_or_buf : the pathname or buffer to write the output
956
956
This can be ``None`` in which case a JSON string is returned
957
-
- orient : The format of the JSON string, default is ``index`` for ``Series``, ``columns`` for ``DataFrame``
957
+
- orient :
958
958
959
-
* split : dict like {index -> [index], columns -> [columns], data -> [values]}
960
-
* records : list like [{column -> value}, ... , {column -> value}]
961
-
* index : dict like {index -> {column -> value}}
962
-
* columns : dict like {column -> {index -> value}}
963
-
* values : just the values array
959
+
Series :
960
+
default is 'index', allowed values are: {'split','records','index'}
961
+
962
+
DataFrame :
963
+
default is 'columns', allowed values are: {'split','records','index','columns','values'}
964
+
965
+
The format of the JSON string
966
+
967
+
* split : dict like {index -> [index], columns -> [columns], data -> [values]}
968
+
* records : list like [{column -> value}, ... , {column -> value}]
969
+
* index : dict like {index -> {column -> value}}
970
+
* columns : dict like {column -> {index -> value}}
971
+
* values : just the values array
964
972
965
973
- date_format : type of date conversion (epoch = epoch milliseconds, iso = ISO8601), default is epoch
966
974
- double_precision : The number of decimal places to use when encoding floating point values, default 10.
@@ -989,6 +997,8 @@ Writing to a file, with a date index and a date column
989
997
990
998
dfj2 = dfj.copy()
991
999
dfj2['date'] = Timestamp('20130101')
1000
+
dfj2['ints'] =range(5)
1001
+
dfj2['bools'] =True
992
1002
dfj2.index = date_range('20130101',periods=5)
993
1003
dfj2.to_json('test.json')
994
1004
open('test.json').read()
@@ -1005,31 +1015,86 @@ is ``None``. To explicity force ``Series`` parsing, pass ``typ=series``
1005
1015
is expected. For instance, a local file could be
1006
1016
file ://localhost/path/to/table.json
1007
1017
- typ : type of object to recover (series or frame), default 'frame'
1008
-
- orient : The format of the JSON string, one of the following
1018
+
- orient :
1019
+
1020
+
Series :
1021
+
default is 'index', allowed values are: {'split','records','index'}
1022
+
1023
+
DataFrame :
1024
+
default is 'columns', allowed values are: {'split','records','index','columns','values'}
1025
+
1026
+
The format of the JSON string
1009
1027
1010
-
* split : dict like {index -> [index], name -> name, data -> [values]}
1011
-
* records : list like [value, ... , value]
1012
-
* index : dict like {index -> value}
1028
+
* split : dict like {index -> [index], columns -> [columns], data -> [values]}
1029
+
* records : list like [{column -> value}, ... , {column -> value}]
1030
+
* index : dict like {index -> {column -> value}}
1031
+
* columns : dict like {column -> {index -> value}}
1032
+
* values : just the values array
1013
1033
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
1034
+
- 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
1035
+
- convert_axes : boolean, try to convert the axes to the proper dtypes, default is True
1036
+
- convert_dates : a list of columns to parse for dates; If True, then try to parse datelike columns, default is True
1017
1037
- keep_default_dates : boolean, default True. If parsing dates, then parse the default datelike columns
1038
+
- numpy: direct decoding to numpy arrays. default is False;
1039
+
Note that the JSON ordering **MUST** be the same for each term if ``numpy=True``
1018
1040
1019
1041
The parser will raise one of ``ValueError/TypeError/AssertionError`` if the JSON is
1020
1042
not parsable.
1021
1043
1044
+
The default of ``convert_axes=True``, ``dtype=True``, and ``convert_dates=True`` will try to parse the axes, and all of the data
1045
+
into appropriate types, including dates. If you need to override specific dtypes, pass a dict to ``dtype``. ``convert_axes`` should only
1046
+
be set to ``False`` if you need to preserve string-like numbers (e.g. '1', '2') in an axes.
1047
+
1048
+
.. warning::
1049
+
1050
+
When reading JSON data, automatic coercing into dtypes has some quirks:
1051
+
1052
+
* an index can be in a different order, that is the returned order is not guaranteed to be the same as before serialization
1053
+
* a column that was ``float`` data can safely be converted to ``integer``, e.g. a column of ``1.``
1054
+
* bool columns will be converted to ``integer`` on reconstruction
1055
+
1056
+
Thus there are times where you may want to specify specific dtypes via the ``dtype`` keyword argument.
1057
+
1022
1058
Reading from a JSON string
1023
1059
1024
1060
.. ipython:: python
1025
1061
1026
1062
pd.read_json(json)
1027
1063
1028
-
Reading from a file, parsing dates
1064
+
Reading from a file
1065
+
1066
+
.. ipython:: python
1067
+
1068
+
pd.read_json('test.json')
1069
+
1070
+
Don't convert any data (but still convert axes and dates)
0 commit comments