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

pandas 时、分、秒数据列上有缺失数据,用自己写填充代码处理时间太长,求如何改进?

  •  
  •   habin · Jan 10, 2019 · 2791 views
    This topic created in 2816 days ago, the information mentioned may be changed or developed.
    DAT_DAY DAT_MONTH DATE_YEAR UTC_HOUR UTC_MIN UTC_MIN_SEC UTC_SEC
    0 4.0 NaN NaN 13.0 NaN NaN NaN
    1 NaN 12.0 17.0 NaN NaN NaN NaN
    2 NaN NaN NaN NaN NaN NaN NaN
    3 NaN NaN NaN NaN 40.0 0:40:27 27.0
    4 4.0 NaN NaN 13.0 NaN NaN NaN


    数据上为递增且连续,例如 0 序号数据应为:4、12、17、13、40、0:40:24、24
    主要是处理时、分、秒数据,求给个方法或思路
    2 replies  •  2019-01-10 10:35:07 +08:00
    BingoXuan
        1
    BingoXuan  
       Jan 10, 2019   ❤️ 1
    先把 index 转换成 datetimeindex,然后从 index 中提取相关信息
    princelai
        2
    princelai  
       Jan 10, 2019   ❤️ 1
    连续且递增?每一条都递增一秒?那就太简单了

    首先手动找出第 0 号数据,就比如你写的那个,这一步要手动找出来

    ```
    dt = pd.datetime(2017,12,4,13,40,24)
    ser = pd.Series([dt]*10000)
    dt2 = pd.Series(map(lambda x:pd.Timedelta(x,unit="s"),ser.index.values)) + ser
    dt2.apply(lambda x:(x.day,x.month,x.year,x.hour))
    ```

    最后一步可以不要,只是用于格式化输出的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2471 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 10:55 · PVG 18:55 · LAX 03:55 · JFK 06:55
    ♥ Do have faith in what you're doing.