Convert a column of datetimes to epoch in Python

前端 未结 3 1025
青春惊慌失措
青春惊慌失措 2020-12-09 04:46

I\'m currently having an issue with Python. I have a Pandas DataFrame and one of the columns is a string with a date. The format is :

\"%Y-%m-%d %H:%m

3条回答
  •  萌比男神i
    2020-12-09 04:56

    I know this is old but I believe the cleanest way is this:

    int(pd.Timestamp("20200918 20:30:05").value/1000000)
    

    Gives 1600461005000 which is the epoch of the date above. The .value attribute is the number of nanoseconds since epoch so we divide by 1e6 to get to milliseconds. Divide by 1e9 if you want epoch in seconds.

提交回复
热议问题