V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2018-02-08 15:58:08 +08:00 · 9464 次点击
    这是一个创建于 2267 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我朋 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 条回复    2018-02-09 14:00:24 +08:00
    wangxxxing
        1
    wangxxxing  
       2018-02-08 17:44:11 +08:00
    有空值 或不能转换的值 报错了
    super452
        2
    super452  
       2018-02-08 17:51:59 +08:00
    先替换或删除异常数据
    shuson
        3
    shuson  
       2018-02-08 17:58:53 +08:00
    有 NaN 的 cell 是不能 convert 成 integer 的,因为 type(np.nan) 是 float

    用 df.fillna(0).astype(int)把 NaN 换成 int 就行了
    jakeyfly
        4
    jakeyfly  
    OP
       2018-02-08 19:00:06 +08:00
    @shuson 了解了 要先把 NAN 填个值是吧
    jakeyfly
        5
    jakeyfly  
    OP
       2018-02-08 19:01:33 +08:00
    @shuson 大佬 如果有十个列 或者更多, 要合半其中几个重复的 然后 别的几个 有的要求合 有的求最小 有的求最大值 这个写出为格式要怎么样啊 是用分组吧
    zachguo
        6
    zachguo  
       2018-02-09 10:07:21 +08:00 via Android
    读取文件的时候设 dtype 为 string
    jakeyfly
        7
    jakeyfly  
    OP
       2018-02-09 14:00:24 +08:00
    @zachguo 大佬 你说的点子上了 读文件的时候 如何设定特定的列的类型 求大佬示范
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3317 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:02 · PVG 22:02 · LAX 07:02 · JFK 10:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.