2

I want to convert the date to epoch ms and attach back to the dataframe how this be done.

     Date
        30/10/2019
        31/10/2019
        04/10/2019
        15/10/2019
        13/11/2019
        3/11/2019

Expected Output:

            Date         Epoch ms
            30/10/2019   1572413051
            31/10/2019
            04/10/2019
            15/10/2019
            13/11/2019
            3/11/2019

    I tried the ones listed reference questions

    import datetime as dt
    dt['epoch'] = (dt['Date'] - dt.datetime(1970,1,1)).dt.total_seconds().


    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-37-77878a892b77> in <module>()
    ----> 1 dt['epoch'] = (dt['Date'] - dt.datetime(1970,1,1)).dt.total_seconds()

TypeError: 'module' object is not subscriptable

How can this be done ?

pankaj
  • 402
  • 1
  • 5
  • 24
  • Refer this - https://datascience.stackexchange.com/questions/19163/pandas-datetime-to-unix – bigbounty Oct 30 '19 at 05:29
  • @Moon, I tried couple of ones listed in reference questions .It giving me an error`TypeError: 'module' object is not subscriptable` – pankaj Oct 30 '19 at 05:54

1 Answers1

1

start with

import datetime

and end with the following. You might need to do some formatting-fu to get different parts of those strings into the function, but I'm confident you can do that if they are delimited the same way.

datetime.datetime(2019,04,01,0,0).strftime('%s')
Rozar Natrim
  • 123
  • 8