Enter search terms or a module, class or function name.
pandas.to_numeric(arg,errors='raise',downcast=None)[source]¶Convert argument to a numeric type.
| Parameters: | arg : list, tuple, 1-d array, or Series errors : {‘ignore’, ‘raise’, ‘coerce’}, default ‘raise’
downcast : {‘integer’, ‘signed’, ‘unsigned’, ‘float’} , default None
|
|---|---|
| Returns: | ret : numeric if parsing succeeded.
|
Examples
Take separate series and convert to numeric, coercing when told to
>>>importpandasaspd>>>s=pd.Series(['1.0','2',-3])>>>pd.to_numeric(s)0 1.01 2.02 -3.0dtype: float64>>>pd.to_numeric(s,downcast='float')0 1.01 2.02 -3.0dtype: float32>>>pd.to_numeric(s,downcast='signed')0 11 22 -3dtype: int8>>>s=pd.Series(['apple','1.0','2',-3])>>>pd.to_numeric(s,errors='ignore')0 apple1 1.02 23 -3dtype: object>>>pd.to_numeric(s,errors='coerce')0 NaN1 1.02 2.03 -3.0dtype: float64