pandas.to_numeric
pandas 3.1.1 · General functions · function
Parse input as numbers. Use errors="coerce" for invalid input and downcast when a smaller numeric dtype is suitable.
Call syntax
pd.to_numeric(arg, errors='raise', downcast=None, dtype_backend=…)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
arg |
Required Positional or keyword |
scalar, list, tuple, 1-d array, Index, or Series Pass a scalar or one-dimensional array-like of numeric values or strings. |
errors |
Optional Positional or keyword Default 'raise' |
{'raise', 'coerce'} Choose "raise" for invalid values or "coerce" to turn them into missing values. |
downcast |
Optional Positional or keyword Default None |
str Choose "integer", "signed", "unsigned", or "float" to use a smaller compatible numeric dtype. |
dtype_backend |
Optional Positional or keyword |
{'numpy_nullable', 'pyarrow'} Choose nullable NumPy-backed dtypes or Arrow-backed dtypes. |
Returns
scalar, Series, Index, numpy.ndarray, or ExtensionArray