Skip to content

Pandas.to_numeric raises ValueError when applied to python Decimal object #14827

Closed
@RogerThomas

Description

@RogerThomas

When pandas tries to convert columns to numeric using to_numeric a value error is raised

Example

import decimal
df = pd.DataFrame(dict(col=[decimal.Decimal(9.1)]))
df['col'] = df['col'].apply(pd.to_numeric)

however

import decimal
df = pd.DataFrame(dict(col=[decimal.Decimal(9.1)]))
df['col'] = df['col'].astype(float)

works fine

Problem description

to_numeric should be able to convert decimal objects to float types

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.12.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-53-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_IE.UTF-8 LOCALE: None.None

pandas: 0.19.1
nose: 1.3.7
pip: 9.0.1
setuptools: 28.3.0
Cython: 0.23.4
numpy: 1.11.2
scipy: 0.16.1
statsmodels: 0.6.1
xarray: None
IPython: None
sphinx: 1.3.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: 3.2.0
numexpr: 2.4.6
matplotlib: 1.5.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: 0.9.2
apiclient: None
sqlalchemy: 1.0.9
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions