@@ -1717,9 +1717,11 @@ def to_json(self, path_or_buf=None, orient=None, date_format=None,
1717
1717
1718
1718
Parameters
1719
1719
----------
1720
- path_or_buf : the path or buffer to write the result string
1721
- if this is None, return the converted string
1720
+ path_or_buf : string or file handle, optional
1721
+ File path or object. If not specified, the result is returned as
1722
+ a string.
1722
1723
orient : string
1724
+ Indication of expected JSON string format.
1723
1725
1724
1726
* Series
1725
1727
@@ -1734,27 +1736,29 @@ def to_json(self, path_or_buf=None, orient=None, date_format=None,
1734
1736
1735
1737
* The format of the JSON string
1736
1738
1737
- - split : dict like
1738
- {index -> [index], columns -> [columns], data -> [values]}
1739
- - records : list like
1739
+ - ' split' : dict like {'index' -> [index],
1740
+ ' columns' -> [columns], ' data' -> [values]}
1741
+ - ' records' : list like
1740
1742
[{column -> value}, ... , {column -> value}]
1741
- - index : dict like {index -> {column -> value}}
1742
- - columns : dict like {column -> {index -> value}}
1743
- - values : just the values array
1744
- - table : dict like {'schema': {schema}, 'data': {data}}
1743
+ - ' index' : dict like {index -> {column -> value}}
1744
+ - ' columns' : dict like {column -> {index -> value}}
1745
+ - ' values' : just the values array
1746
+ - ' table' : dict like {'schema': {schema}, 'data': {data}}
1745
1747
describing the data, and the data component is
1746
1748
like ``orient='records'``.
1747
1749
1748
1750
.. versionchanged:: 0.20.0
1749
1751
1750
1752
date_format : {None, 'epoch', 'iso'}
1751
- Type of date conversion. `epoch` = epoch milliseconds,
1752
- `iso` = ISO8601. The default depends on the `orient`. For
1753
- `orient='table'`, the default is `'iso'`. For all other orients,
1754
- the default is `'epoch'`.
1755
- double_precision : The number of decimal places to use when encoding
1756
- floating point values, default 10.
1757
- force_ascii : force encoded string to be ASCII, default True.
1753
+ Type of date conversion. 'epoch' = epoch milliseconds,
1754
+ 'iso' = ISO8601. The default depends on the `orient`. For
1755
+ ``orient='table'``, the default is 'iso'. For all other orients,
1756
+ the default is 'epoch'.
1757
+ double_precision : int, default 10
1758
+ The number of decimal places to use when encoding
1759
+ floating point values.
1760
+ force_ascii : boolean, default True
1761
+ Force encoded string to be ASCII.
1758
1762
date_unit : string, default 'ms' (milliseconds)
1759
1763
The time unit to encode to, governs timestamp and ISO8601
1760
1764
precision. One of 's', 'ms', 'us', 'ns' for second, millisecond,
@@ -1783,13 +1787,9 @@ def to_json(self, path_or_buf=None, orient=None, date_format=None,
1783
1787
1784
1788
.. versionadded:: 0.23.0
1785
1789
1786
- Returns
1787
- -------
1788
- same type as input object with filtered info axis
1789
-
1790
1790
See Also
1791
1791
--------
1792
- pd .read_json
1792
+ pandas .read_json
1793
1793
1794
1794
Examples
1795
1795
--------
@@ -1802,16 +1802,26 @@ def to_json(self, path_or_buf=None, orient=None, date_format=None,
1802
1802
"index":["row 1","row 2"],
1803
1803
"data":[["a","b"],["c","d"]]}'
1804
1804
1805
+ Encoding/decoding a Dataframe using ``'records'`` formatted JSON.
1806
+ Note that index labels are not preserved with this encoding.
1807
+
1808
+ >>> df.to_json(orient='records')
1809
+ '[{"col 1":"a","col 2":"b"},{"col 1":"c","col 2":"d"}]'
1810
+
1805
1811
Encoding/decoding a Dataframe using ``'index'`` formatted JSON:
1806
1812
1807
1813
>>> df.to_json(orient='index')
1808
1814
'{"row 1":{"col 1":"a","col 2":"b"},"row 2":{"col 1":"c","col 2":"d"}}'
1809
1815
1810
- Encoding/decoding a Dataframe using ``'records'`` formatted JSON.
1811
- Note that index labels are not preserved with this encoding.
1816
+ Encoding/decoding a Dataframe using ``'columns'`` formatted JSON:
1812
1817
1813
- >>> df.to_json(orient='records')
1814
- '[{"col 1":"a","col 2":"b"},{"col 1":"c","col 2":"d"}]'
1818
+ >>> df.to_json(orient='columns')
1819
+ '{"col 1":{"row 1":"a","row 2":"c"},"col 2":{"row 1":"b","row 2":"d"}}'
1820
+
1821
+ Encoding/decoding a Dataframe using ``'values'`` formatted JSON:
1822
+
1823
+ >>> df.to_json(orient='values')
1824
+ '[["a","b"],["c","d"]]'
1815
1825
1816
1826
Encoding with Table Schema
1817
1827
0 commit comments