推荐学习书目
› 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
LunarG
V2EX  ›  Python

是我记忆混乱了还是 Pandas 更新了 read_csv()?

  •  
  •   LunarG · Feb 8, 2021 · 2621 views
    This topic created in 2068 days ago, the information mentioned may be changed or developed.

    今天用read_csv()读一个to_csv()生成的文件的时候,发现 columns 不一致。

    文件的 header 是:id, high, low, open, close, count, amount, volume

    用read_csv()读出来的 header 是:Index(['id', ' high', ' low', ' open', ' close', ' count', ' amount', ' volume'], dtype='object')

    也就是在原有 header 的前面多了个空格,翻了下更新,也没有关于这个的说明。现在需要加一个 skipinitialspace=True,我明明记得之前可以直接读的啊?

    Pandas 1.2.1

    3 replies  •  2021-02-09 16:57:08 +08:00
    sunmlight
        1
    sunmlight  
       Feb 8, 2021
    你的表头换成这个就没空格了:id,high,low,open,close,count,amount,volume
    LunarG
        2
    LunarG  
    OP
       Feb 8, 2021
    @sunmlight 是的,但是我以前也是直接 to_csv,它也认得呀?我以为我记错了,我找朋友问了下都是说以前不需要这样
    Yinz
        3
    Yinz  
       Feb 9, 2021
    不是 read_csv 的问题,是你的 csv header 有空格,我试了下 1.2.1 的 to_csv 生成出来没空格,你仔细看看你生成 csv 的地方吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   962 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 87ms · UTC 19:01 · PVG 03:01 · LAX 12:01 · JFK 15:01
    ♥ Do have faith in what you're doing.