Search code examples
pythonpython-3.xpandasdataframepython-datetime

convert object (numeric value) to datetime using pandas


I have the data with time column as shown below, how to convert this as date and time using pandas

datetime


Solution

  • Consider df:

    In [208]: df
    Out[208]: 
             Time
    0  2384798300
    1  1500353475
    2  7006557825
    3  1239779541
    4  1237529231
    

    Use datetime.fromtimestamp with df.apply:

    In [200]: from datetime import datetime
    
    In [209]: df['Time'] = df['Time'].apply(lambda x: datetime.fromtimestamp(x))
    
    In [210]: df
    Out[210]: 
                       Time
    0   2045-07-28 01:28:20
    1   2017-07-18 10:21:15
    2   2192-01-11 15:33:45
    3   2009-04-15 12:42:21
    4   2009-03-20 11:37:11