推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
jakeyfly
V2EX  ›  Python

PANDAS 刚刚学着用 改类型出错 求大佬指导

  •  
  •   jakeyfly · Feb 8, 2018 · 10693 views
    This topic created in 3152 days ago, the information mentioned may be changed or developed.

    我朋 EXCEL 表格导入一个表 有一列是电话号码,倒入后全变成 1.xxxxxxxxxx 这样的小数了 我想把这列的类型改成 int 就报错 如下 求解答 raise ValueError('Cannot convert non-finite values (NA or inf) to ' ValueError: Cannot convert non-finite values (NA or inf) to integer

    7 replies  •  2018-02-09 14:00:24 +08:00
    uxgnok
        1
    uxgnok  
       Feb 8, 2018
    有空值 或不能转换的值 报错了
    super452
        2
    super452  
       Feb 8, 2018
    先替换或删除异常数据
    shuson
        3
    shuson  
       Feb 8, 2018
    有 NaN 的 cell 是不能 convert 成 integer 的,因为 type(np.nan) 是 float

    用 df.fillna(0).astype(int)把 NaN 换成 int 就行了
    jakeyfly
        4
    jakeyfly  
    OP
       Feb 8, 2018
    @shuson 了解了 要先把 NAN 填个值是吧
    jakeyfly
        5
    jakeyfly  
    OP
       Feb 8, 2018
    @shuson 大佬 如果有十个列 或者更多, 要合半其中几个重复的 然后 别的几个 有的要求合 有的求最小 有的求最大值 这个写出为格式要怎么样啊 是用分组吧
    zachguo
        6
    zachguo  
       Feb 9, 2018 via Android
    读取文件的时候设 dtype 为 string
    jakeyfly
        7
    jakeyfly  
    OP
       Feb 9, 2018
    @zachguo 大佬 你说的点子上了 读文件的时候 如何设定特定的列的类型 求大佬示范
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2572 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 09:32 · PVG 17:32 · LAX 02:32 · JFK 05:32
    ♥ Do have faith in what you're doing.