美文网首页
【2019-01-26】时间特征处理

【2019-01-26】时间特征处理

作者: BigBigFlower | 来源:发表于2019-01-26 22:09 被阅读0次

    原始数据格式:

    原始数据

    (1)读取数据

    x['survey_time'].values

    array(['2015/8/4 14:18', '2015/7/21 15:04', '2015/7/21 13:24', ..., '2015/8/1 17:48', '2015/9/22 18:52', '2015/9/28 20:22'],  dtype=object)

    (2)读取时间格式

    pd.DatetimeIndex(x['survey_time'])

    DatetimeIndex(['2015-08-04 14:18:00', '2015-07-21 15:04:00','2015-07-21 13:24:00', '2015-07-25 17:33:00', '2015-08-10 09:50:00', '2015-07-18 12:09:00', '2015-07-26 14:51:00', '2015-07-19 13:12:00',    '2015-08-01 09:25:00', '2015-08-03 19:23:00', ... '2015-07-25 19:54:00', '2015-07-21 11:14:00', '2015-08-30 15:35:00', '2015-07-19 07:45:00', '2015-07-12 17:30:00', '2015-07-21 19:36:00','2015-07-31 16:00:00', '2015-08-01 17:48:00','2015-09-22 18:52:00', '2015-09-28 20:22:00'],dtype='datetime64[ns]', name='survey_time', length=8000, freq=None)

    (3)读取日期

    pd.DatetimeIndex(x['survey_time']).date

    array([datetime.date(2015, 8, 4), datetime.date(2015, 7, 21),datetime.date(2015, 7, 21), ..., datetime.date(2015, 8, 1),datetime.date(2015, 9, 22), datetime.date(2015, 9, 28)],dtype=object)

    (4)读取时间

    pd.DatetimeIndex(x['survey_time']).time

    array([datetime.time(14, 18), datetime.time(15, 4), datetime.time(13, 24),...,datetime.time(17, 48), datetime.time(18, 52), datetime.time(20, 22)], dtype=object)

    (5)取出月份

    h=pd.DatetimeIndex(k)

    h.month

    Int64Index([8, 7, 7, 7, 8, 7, 7, 7, 8, 8, ...7, 7, 8, 7, 7, 7, 7, 8, 9, 9],dtype='int64', length=8000)

    相关文章

      网友评论

          本文标题:【2019-01-26】时间特征处理

          本文链接:https://www.haomeiwen.com/subject/nvdwjqtx.html