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
youthfire
V2EX  ›  Python

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

  •  
  •   youthfire · 2019-08-29 16:17:39 +08:00 · 3410 次点击
    这是一个创建于 1694 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    3 条回复    2019-08-30 22:39:18 +08:00
    0DBBFF
        1
    0DBBFF  
       2019-08-29 16:47:45 +08:00   ❤️ 1
    df['日期'] = df['日期'].map(lambda x: time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(x)))
    Aeoluze
        2
    Aeoluze  
       2019-08-29 18:19:22 +08:00   ❤️ 1
    格式改为 df.Timestamp 就行
    Pandas 有 df.astype.('datetime64')
    jiang123574
        3
    jiang123574  
       2019-08-30 22:39:18 +08:00
    pd.read_excel(excel,parse_dates=[7]) 试一下,如果能正确读取就是对的,如果不能正确读取 说明是 1900-01-01 的天数值 需要用这个数字记为天数 然后加上 1900-01-01
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3773 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:05 · PVG 13:05 · LAX 22:05 · JFK 01:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.