博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pandas.to_numeric转化数据为数字型
阅读量:6893 次
发布时间:2019-06-27

本文共 2193 字,大约阅读时间需要 7 分钟。

to_numeric(arg, errors='raise', downcast=None)
    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
    downcast : {'integer', 'signed', 'unsigned', 'float'} , default None
        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:
    
        - 'integer' or 'signed': smallest signed int dtype (min.: np.int8)
        - 'unsigned': smallest unsigned int dtype (min.: np.uint8)
        - 'float': smallest float dtype (min.: np.float32)
    
        As this behaviour is separate from the core conversion to
        numeric values, any errors raised during the downcasting
        will be surfaced regardless of the value of the 'errors' input.
    
        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.
    
        .. versionadded:: 0.19.0
    
    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)
    0    1.0
    1    2.0
    2   -3.0
    dtype: float64
    >>> pd.to_numeric(s, downcast='float')
    0    1.0
    1    2.0
    2   -3.0
    dtype: float32
    >>> pd.to_numeric(s, downcast='signed')
    0    1
    1    2
    2   -3
    dtype: int8
    >>> s = pd.Series(['apple', '1.0', '2', -3])
    >>> pd.to_numeric(s, errors='ignore')
    0    apple
    1      1.0
    2        2
    3       -3
    dtype: object
    >>> pd.to_numeric(s, errors='coerce')
    0    NaN
    1    1.0
    2    2.0
    3   -3.0
    dtype: float64
    
    See also
    --------
    pandas.DataFrame.astype : Cast argument to a specified dtype.
    pandas.to_datetime : Convert argument to datetime.
    pandas.to_timedelta : Convert argument to timedelta.
    numpy.ndarray.astype : Cast a numpy array to a specified type.

转载地址:http://zhkdl.baihongyu.com/

你可能感兴趣的文章
如何减少返工工作量?
查看>>
《敏捷可执行需求说明 Scrum提炼及实现技术》—— 2.1 界定不可更改的边界
查看>>
关注安防行业 聚焦公共安防系统
查看>>
Android代码(Handler的运用),HttpURLConnection的应用,将url图片地址转换成图片。...
查看>>
MySQL锁系列(七)之 锁算法详解
查看>>
webOS 更名 LuneOS,新版本名为 Affogato
查看>>
《UNIX环境高级编程(第3版)》——导读
查看>>
11_Eclipse中演示Git版本的创建,历史版本的修改,创建分支,合并历史版本和当前版本...
查看>>
《实施Cisco统一通信管理器(CIPT1)》一1.2 CUCM概述
查看>>
《容器技术系列》一1.1 引言
查看>>
Ceylon IDE 1.2.0 首个维护版本发布
查看>>
《SolidWorks 2016中文版机械设计从入门到精通》——1.8 参考点
查看>>
《互联网+流通——F2R助力传统产业创新与转型》一一1.1 “互联网+”的本质、演进与发展趋势...
查看>>
在经历诸多坑后,Sonar@OSC 重新上线
查看>>
超过 35 万软件包 npm 是世界上最大的包管理器
查看>>
《SolidWorks 2017中文版机械设计从入门到精通)》——1.8 参考点
查看>>
《CUDA C编程权威指南》——2.3 组织并行线程
查看>>
Popcorn Time 的 Github 库被 MPAA 关闭
查看>>
《CMOS集成电路后端设计与实战》——第3章 后端全定制设计之标准单元设计技术...
查看>>
渲染 React 组件到 Sketch 的开源库 React Sketch.app
查看>>