pandas.to_numeric()

pandas.to_numeric

pandas.to_numeric(arg, errors='raise')

Convert argument to a numeric type.

Parameters:

arg : list, tuple, 1-d array, or Series

errors : {‘ignore’, ‘raise’, ‘coerce’}, default ‘raise’

  • If ‘raise’, then invalid parsing will raise an exception
  • If ‘coerce’, then invalid parsing will be set as NaN
  • If ‘ignore’, then invalid parsing will return the input
Returns:

ret : numeric if parsing succeeded.

Return type depends on input. Series if Series, otherwise ndarray

Examples

Take separate series and convert to numeric, coercing when told to

>>> import pandas as pd
>>> s = pd.Series(['1.0', '2', -3])
>>> pd.to_numeric(s)
>>> s = pd.Series(['apple', '1.0', '2', -3])
>>> pd.to_numeric(s, errors='ignore')
>>> pd.to_numeric(s, errors='coerce')

© 2011–2012 Lambda Foundry, Inc. and PyData Development Team
© 2008–2011 AQR Capital Management, LLC
© 2008–2014 the pandas development team
Licensed under the 3-clause BSD License.
http://pandas.pydata.org/pandas-docs/version/0.18.1/generated/pandas.to_numeric.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部