Pandas: Data Manipulation - to_numeric() function
to_numeric() function
The to_numeric() function is used tp convert argument to a numeric type.
The default return dtype is float64 or int64 depending on the data supplied. Use the downcast parameter to obtain other dtypes.
Due to the internal limitations of ndarray, if numbers smaller than -9223372036854775808 (np.iinfo(np.int64).min) or larger than 18446744073709551615 (np.iinfo(np.uint64).max) are passed in, it is very likely they will be converted to float so that they can stored in an ndarray. These warnings apply similarly to Series since it internally leverages ndarray.
Syntax:
pandas.to_numeric(arg, errors='raise', downcast=None)
Parameters:
Name | Description | Type / Default Value | Required / Optional |
---|---|---|---|
arg | scalar, list, tuple, 1-d array, or Series | Required | |
errors |
|
{'ignore', 'raise', 'coerce'}, Default Value: 'raise' |
Required |
downcst | If not None, and if the data has been successfully cast to a numerical dtype (or if the data was numeric to begin with), downcast that resulting data to the smallest numerical dtype possible according to the following rules:
In addition, downcasting will only occur if the size of the resulting data’s dtype is strictly larger than the dtype it is to be cast to, so if none of the dtypes checked satisfy that specification, no downcasting will be performed on the data. |
{‘integer’, ‘signed’, ‘unsigned’, ‘float’} , Default Value: None |
Required |
Returns: ret : numeric if parsing succeeded.
Return type depends on input. Series if Series, otherwise ndarray.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: notnull() function
Next: to_datetime() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/pandas/to_numeric.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics