Converting Pandas DatetimeIndex to a numeric format

前端 未结 5 2079
遥遥无期
遥遥无期 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条回答
  •  星月不相逢
    2021-01-05 08:25

    I believe this offers another solution, here assuming a dataframe with a DatetimeIndex.

    pd.to_numeric(df.index, downcast='float')
    # although normally I would prefer an integer, and to coerce errors to NaN
    pd.to_numeric(df.index, errors = 'coerce',downcast='integer')
    

提交回复
热议问题