How do I convert timestamp to datetime.date in pandas dataframe?

前端 未结 7 1808
清酒与你
清酒与你 2020-12-03 14:03

I need to merge 2 pandas dataframes together on dates, but they currently have different date types. 1 is timestamp (imported from excel) and the other is datetime.dat

相关标签:
7条回答
  • 2020-12-03 14:50

    Assume time column is in timestamp integer msec format

    1 day = 86400000 ms

    Here you go:

    day_divider = 86400000
    
    df['time'] = df['time'].values.astype(dtype='datetime64[ms]') # for msec format
    
    df['time'] = (df['time']/day_divider).values.astype(dtype='datetime64[D]') # for day format
    
    0 讨论(0)
提交回复
热议问题