【问题标题】:Graphlab Date ManipulaitonGraphlab 日期操作
【发布时间】:2016-08-04 11:18:10
【问题描述】:

我有一个dataset,我正试图在 GraphLab 中对其进行操作。我想将输入文件 (转换为 SFrame) 中的 UNIX Epoch 时间戳转换为人类可读的格式,以便我可以根据一天中的小时和一周中的一天进行分析。

time_array 是 SFrame sf 的列/特征,代表时间戳,我已经打破了 EPOCH 时间以简化事情。我知道如何转换一行的时间,但我想要一个向量运算。这是我的一排。

time_array = sf['timestamp']

datetime.datetime.fromtimestamp(time_array[0]).strftime('%Y-%m-%d %H')

【问题讨论】:

    标签: python-2.7 graphlab


    【解决方案1】:

    您还可以从时间戳中获取部分时间,以创建另一列,通过该列进行过滤(例如,获取小时):

    sf['hour'] = [x.strftime('%H')for x in sf['timestamp']]
    

    【讨论】:

      【解决方案2】:

      因此,在盯着这个问题看了一会儿,然后发布了它来找我的问题,希望其他人也能从中受益。将.apply 方法与datetime.datetime() 函数一起使用

      sf['date_string'] = sf['timestamp'].apply(lambda x:    datetime.datetime.fromtimestamp(x).strftime('%Y-%m-%d %H'))
      

      【讨论】:

      • 您还可以从时间戳中获取部分时间来创建另一列,通过该列进行过滤(例如,获取小时):sf['hour'] = [x.strftime('% H')for x in sf['timestamp']]
      【解决方案3】:

      您还可以使用split_datetime API 将时间戳拆分为多列:

      split_datetime('timestamp',limit=['hour','minute'])
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-18
        • 2017-08-17
        • 2015-05-06
        • 1970-01-01
        • 2016-02-20
        • 2010-09-10
        • 2011-02-06
        相关资源
        最近更新 更多