-2

I have unix timestamps that starts from 1970-01-01 in csv file as column. I want their corresponding date-time but when I am using pd.to_datetime() I am getting date something like this: 1970-01-16 20:55:29.694.

Sreeram TP
  • 11,346
  • 7
  • 54
  • 108

1 Answers1

0

From your affirmation, I will assume that you want to extract something specific (let's keep it in the same format) from the output of pd.to_datetime() or use another pandas function.

If this is the case, I would proceed as follows :

    import pandas as pd
    t = '2018-07-25' # your excel date
    t_ex = pd.Timestamp(t) 
    # t_ex == 2018-07-25 00:00:00
    t_ex_format = m = str(t_ex.year)+'-'+str(t_ex.month)+'-'+str(t_ex.day) 
    # t_ex_format = 2018-07-25
FlyingZipper
  • 701
  • 6
  • 26
  • Thanks for the answer. Sorry I didnt asked my question properly. I have a column of timestamp which has unix timestamps( eg. 1364099483). I want to convert this to its corresponding date-time which should is 24 March 2013 04:31:23. But the result which I am getting is 1/16/1970 18:54. Code which I am using for this is: dataset['DATE']=(pd.to_datetime(dataset['timestamp'],unit='ms')) – Saurabh Singh Sep 25 '18 at 16:01
  • Thanks. It was done, I was not passing the origin parameter. – Saurabh Singh Sep 25 '18 at 18:26