-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
to_dict doesn't convert np.int64 to python integers #16048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you're only dumping to JSON, then |
Sadly there is no orient I could use in to_json. |
@kszucs I think that has been fixed recently FYI: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_json.html |
Still observe the same behavior (numpy.int64 instead of python int type) in current pandas 0.23.4. |
I am having the same issue. I have to convert CSV output to dict, doing it with pandas (df.to_dict('records')) gives me in one case correct python types, in the other case still leaves the types as numpy. Is there any workaround at all? I cannot find proper documentation on how to user pandas.compat with pandas method to_dict. |
For posterity, I ended up doing something like |
use: |
Code Sample, a copy-pastable example if possible
Problem description
depending on the count of output columns, numpy integers getting converted to python integers
afterwards both
json.dumps
andujson.dumps
fails to encodeExpected Output
int for both cases
Output of
pd.show_versions()
pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 33.1.1.post20170320
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
statsmodels: 0.8.0
xarray: None
IPython: 5.3.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.2
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.1.9
pymysql: 0.7.10.None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.9.5
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: