How to change the datetime format in Pandas

My dataframe has a DOB column (example format 1/1/2016) which by default gets converted to Pandas dtype ‘object’. Converting this to date format with df[‘DOB’] = pd.to_datetime(df[‘DOB’]), the date gets converted to: 2016-01-26 and its dtype is: datetime64[ns]. Now I want to convert this date format to 01/26/2016 or any other general date format. How … Read more

Convert python datetime to epoch with strftime

I have a time in UTC from which I want the number of seconds since epoch. I am using strftime to convert it to the number of seconds. Taking 1st April 2012 as an example. >>>datetime.datetime(2012,04,01,0,0).strftime(‘%s’) ‘1333234800’ 1st of April 2012 UTC from epoch is 1333238400 but this above returns 1333234800 which is different by … Read more

Converting unix timestamp string to readable date

I have a string representing a unix timestamp (i.e. “1284101485”) in Python, and I’d like to convert it to a readable date. When I use time.strftime, I get a TypeError: >>>import time >>>print time.strftime(“%B %d %Y”, “1284101485”) Traceback (most recent call last): File “<stdin>”, line 1, in <module> TypeError: argument must be 9-item sequence, not … Read more