V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 10328 views
    This topic created in 3006 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   ·   Solana   ·   2649 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 64ms · UTC 03:48 · PVG 11:48 · LAX 20:48 · JFK 23:48
    ♥ Do have faith in what you're doing.