Converting Pandas DatetimeIndex to a numeric format

前端 未结 5 2111
遥遥无期
遥遥无期 2021-01-05 07:30

I want to convert the DatetimeIndex in my DataFrame to float format,which can be analysed in my model.Could someone tell me how to do it? Do I need to use date2num()functio

5条回答
  •  萌比男神i
    2021-01-05 08:21

    If you only want specific parts of your DateTimeIndex, try this:

    ADDITIONAL = 1
    ddf_c['ts_part_numeric'] = ((ddf_c.index.dt.year * (10000 * ADDITIONAL)) + (ddf_c.index.dt.month * (100 * ADDITIONAL)) + ((ddf_c.index.dt.day) * ADDITIONAL))
    

    Output is

    20190523
    20190524
    

    Could adjust it to your time resolution needed.

提交回复
热议问题