Skip to content

Commit 2379146

Browse files
Dharni0607Yi Wei
authored and
Yi Wei
committed
DOC: Adding examples for dtype_backend="pyarrow" for read_json() (pandas-dev#52813)
1 parent 76a1acf commit 2379146

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

doc/source/user_guide/io.rst

+15-2
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ pass ``format='mixed'``
998998

999999
.. ipython:: python
10001000
1001-
data = io.StringIO("date\n12 Jan 2000\n2000-01-13\n")
1001+
data = StringIO("date\n12 Jan 2000\n2000-01-13\n")
10021002
df = pd.read_csv(data)
10031003
df['date'] = pd.to_datetime(df['date'], format='mixed')
10041004
df
@@ -1007,7 +1007,7 @@ or, if your datetime formats are all ISO8601 (possibly not identically-formatted
10071007

10081008
.. ipython:: python
10091009
1010-
data = io.StringIO("date\n2020-01-01\n2020-01-01 03:00\n")
1010+
data = StringIO("date\n2020-01-01\n2020-01-01 03:00\n")
10111011
df = pd.read_csv(data)
10121012
df['date'] = pd.to_datetime(df['date'], format='ISO8601')
10131013
df
@@ -2167,6 +2167,19 @@ Dates written in nanoseconds need to be read back in nanoseconds:
21672167
dfju = pd.read_json(json, date_unit="ns")
21682168
dfju
21692169
2170+
By setting the ``dtype_backend`` argument you can control the default dtypes used for the resulting DataFrame.
2171+
2172+
.. ipython:: python
2173+
2174+
data = (
2175+
'{"a":{"0":1,"1":3},"b":{"0":2.5,"1":4.5},"c":{"0":true,"1":false},"d":{"0":"a","1":"b"},'
2176+
'"e":{"0":null,"1":6.0},"f":{"0":null,"1":7.5},"g":{"0":null,"1":true},"h":{"0":null,"1":"a"},'
2177+
'"i":{"0":"12-31-2019","1":"12-31-2019"},"j":{"0":null,"1":null}}'
2178+
)
2179+
df = pd.read_json(StringIO(data), dtype_backend="pyarrow")
2180+
df
2181+
df.dtypes
2182+
21702183
.. _io.json_normalize:
21712184

21722185
Normalization

0 commit comments

Comments
 (0)