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

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

  •  
  •   habin · 2019-01-10 09:44:09 +08:00 · 1719 次点击
    这是一个创建于 1904 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2019-01-10 10:35:07 +08:00
    BingoXuan
        1
    BingoXuan  
       2019-01-10 10:27:19 +08:00   ❤️ 1
    先把 index 转换成 datetimeindex,然后从 index 中提取相关信息
    princelai
        2
    princelai  
       2019-01-10 10:35:07 +08:00   ❤️ 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))
    ```

    最后一步可以不要,只是用于格式化输出的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   960 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 21:52 · PVG 05:52 · LAX 14:52 · JFK 17:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.