How do I properly set the Datetimeindex for a Pandas datetime object in a dataframe?

后端 未结 2 2017
醉话见心
醉话见心 2021-01-30 05:14

I have a pandas dataframe:

    lat         lng         alt days              date        time
0   40.003834   116.321462  211 39745.175405      2008-10-24  04:12         


        
2条回答
  •  清酒与你
    2021-01-30 05:39

    You are not creating datetime index properly,

    format = '%Y-%m-%d %H:%M:%S'
    df['Datetime'] = pd.to_datetime(df['date'] + ' ' + df['time'], format=format)
    df = df.set_index(pd.DatetimeIndex(df['Datetime']))
    

提交回复
热议问题