-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
DataFrame.to_dict(orient='records') numeric inconsistency #22620
Labels
Milestone
Comments
ref to #13468, probably some other open issues - we should always be converting to native types. As a workaround, iterating/constructing row-by-row seems to work. dict_no_obj2 = [x.to_dict()
for _, x in df.drop(columns=['c']).iterrows()]
print((type(dict_no_obj2[0]['a']), type(dict_no_obj2[0]['b'])))
# (<class 'float'>, <class 'float'>) |
ref #21256, likely same underlying issue |
Looks fixed on master. Could use a test.
|
sofiane87
added a commit
to sofiane87/pandas
that referenced
this issue
Nov 2, 2019
4 tasks
jreback
pushed a commit
that referenced
this issue
Nov 5, 2019
Reksbril
pushed a commit
to Reksbril/pandas
that referenced
this issue
Nov 18, 2019
proost
pushed a commit
to proost/pandas
that referenced
this issue
Dec 19, 2019
proost
pushed a commit
to proost/pandas
that referenced
this issue
Dec 19, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code Sample, a copy-pastable example if possible
Similar to #11247, but related to numerics. If there are any object columns in the DataFrame, then numerical columns are turned into native types, whereas if all columns are numpy numerics, they stay that way:
Output:
Problem description
I need to combine the output dictionary with other dictionaries, and then convert it to JSON (using
ujson.dumps
). Sinceujson
cannot handle NumPy types, it crashes. Since I need to post process the output ofto_dict
before converting to JSON unfortunatelydf.to_json
is not an option.Expected Output
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit: None
python: 3.7.0.final.0
python-bits: 64
OS: Darwin
OS-release: 17.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8
pandas: 0.23.3
pytest: None
pip: 18.0
setuptools: 40.0.0
Cython: 0.28.5
numpy: 1.15.0
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: