Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
import pandas as pd
df = pd.read_json('file.jsonl', orient='records', lines=True)
df['uuid']
Problem description
I have a jsonlines
file (file.jsonl
) that looks like this
{"id": 1, "uuid": "1344800117571260417"}
{"id": 2, "uuid": "1344900117571260918"}
After reading that file using the above code, this is what I get:
id uuid
0 1 1344800117571260416
1 2 1344900117571260928
So the uuid
s have changed
Expected Output
My output should look like
id uuid
0 1 1344800117571260417
1 2 1344900117571260918
On Stackoverflow, someone answered my post, with the following explanation:
int(float("1344900117571260918")) is 1344900117571260928 . I assume pandas first uses floats and afterwards converts it to int - so precision is lost.
So the problem is how pandas
is inferring the types.
Output of pd.show_versions()
pandas : 1.2.4
numpy : 1.18.5
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.2.0.post20200210
Cython : 0.29.15
pytest : 5.4.3
hypothesis : 5.5.4
sphinx : 2.4.0
blosc : None
feather : None
xlsxwriter : 1.2.7
lxml.etree : 4.5.2
html5lib : 1.0.1
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : 2.11.1
IPython : 7.12.0
pandas_datareader: None
bs4 : 4.8.2
bottleneck : 1.3.2
fsspec : 0.6.2
fastparquet : None
gcsfs : None
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : 3.6.1
tabulate : 0.8.7
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.48.0