Description
Code Sample
import pandas
import json
d = {'col1': [13342205958987758245, 12388075603347835679], 'col2': [13342204859476130034, 12388075603347835679]}
df = pandas.DataFrame(data=d)
print (df)
print (df.dtypes)
print ("--- to json output")
print (df.head(5).fillna('NULL').to_json(orient='split'))
print ("--- to dict output")
print (json.dumps(df.head(5).fillna('NULL').to_dict(orient='split')))
Problem description
the output of the above code is :
Col1 Col2
0 13342205958987758245 12388075603347835679
1 13342204859476130034 12388075603347835679
--- dtypes
Col1 uint64
Col2 uint64
dtype: object
--- to json output
{"columns":["Col1","Col2"],"index":[0,1,2,3,4],"data":[[-5104538114721793371,-6058668470361715937],[-5104539214233421582,-6058668470361715937],[-5104583194698550022,-6058668470361715937],[-3637227675748224855,-6058668470361715937],[-6228767139342072872,-6058667370850087726]]}
--- to dict output
{"index": [0, 1, 2, 3, 4], "data": [[13342205958987758245, 12388075603347835679], [13342204859476130034, 12388075603347835679], [13342160879011001594, 12388075603347835679], [14809516397961326761, 12388075603347835679], [12217976934367478744, 12388076702859463890]], "columns": ["Col1", "Col2"]}
you can see the data are different for these two similar functions: to_json
and to_dict
.
I believe that the output of to_dict
is correct but to_json
has change my original digits.
Expected Output
The expected output is what we see in the to_dict
output.
Output of pd.show_versions()
[paste the output of pd.show_versions()
here below this line]
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.14.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.5.0
Cython: None
numpy: 1.14.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: 1.0.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: None
bs4: None
html5lib: None
sqlalchemy: 0.8.0
pymysql: None
psycopg2: None
jinja2: 2.7.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None