Date Time split in python

前端 未结 5 1595
再見小時候
再見小時候 2021-02-07 22:58

I have to split a date time which I get from a software in the below format to separate variables (year,month,day,hour, min,sec)

19 Nov 2015  18:45:00.000
         


        
5条回答
  •  春和景丽
    2021-02-07 23:33

    df2['invoice_date']=pd.to_datetime(df2.invoice_date, format='%m/%d/%Y %H:%M')
    
    
    df2.insert(loc=5, column='month', value=df2.invoice_date.dt.month)
    # +1 to make Monday=1.....until Sunday=7
        df2.insert(loc=6, column='day', value=(df2.invoice_date.dt.dayofweek)+1)
        df2.insert(loc=7, column='hour', value=df2.invoice_date.dt.hour)
    

提交回复
热议问题