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

求教怎样用 Pandas 批量修改 Excel 中某一列的属性为日期格式并保存下来

  •  
  •   youthfire · Aug 29, 2019 · 3943 views
    This topic created in 2479 days ago, the information mentioned may be changed or developed.

    有上百个 Excel,数据都很规范,除了第 8 列,应该显示为“日期”的显示的是一串数字。

    手工改的话,就是选中这列,属性中把“常规”改为“日期”即显示为正常日期。

    求教怎样用 Pandas 进行批量修正?谢谢

    3 replies    2019-08-30 22:39:18 +08:00
    0DBBFF
        1
    0DBBFF  
       Aug 29, 2019   ❤️ 1
    df['日期'] = df['日期'].map(lambda x: time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(x)))
    Aeoluze
        2
    Aeoluze  
       Aug 29, 2019   ❤️ 1
    格式改为 df.Timestamp 就行
    Pandas 有 df.astype.('datetime64')
    jiang123574
        3
    jiang123574  
       Aug 30, 2019
    pd.read_excel(excel,parse_dates=[7]) 试一下,如果能正确读取就是对的,如果不能正确读取 说明是 1900-01-01 的天数值 需要用这个数字记为天数 然后加上 1900-01-01
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3010 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 73ms · UTC 05:07 · PVG 13:07 · LAX 22:07 · JFK 01:07
    ♥ Do have faith in what you're doing.