【问题标题】:More efficient way to round to day timestamps using pandas使用 pandas 更有效地舍入每日时间戳的方法
【发布时间】:2015-07-20 21:16:14
【问题描述】:

我已将一些时间戳导入 Pandas 框架(通过 MongoDBclient)。它们是微秒级的。我想要一种方法来结束这一天。我已经看到了一个关于在转换为整数并再次返回时使用np.round 的先前问题,但这不起作用(我尝试将 div 内联 3600 x 24 x 100000 但这不起作用)。

我有这个相当简单的版本,但它似乎真的效率低下。我在to_datetime 或np.round 示例中缺少什么。

df['doa'] = df['doa'].map(lambda x: x.strftime("%Y-%m-%d")
pd.to_datetime(df['doa'])

注意,这些不是索引,所以我不能使用频率技巧。

【问题讨论】:

    标签: python datetime pandas


    【解决方案1】:

    有这个功能请求,这表明没有好的方法: ENH: add rounding method to DatetimeIndex/TimedeltaIndex

    但是,在文章中我发现分钟也有这种方法,我也许可以修改:

    pd.DatetimeIndex(((dti.asi8/(1e9*60)).round()*1e9*60).astype(np.int64))

    Rounding Pandas Timestamp to minutes

    【讨论】:

      猜你喜欢
      • 2018-09-09
      • 1970-01-01
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2017-04-14
      相关资源
      最近更新 更多