Python Pandas datetime - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Python Pandas datetime (/thread-1473.html) |
Python Pandas datetime - nuncio - Jan-06-2017 I have some data which I read in pandas like this data = pd.read_table('filename.txt', sep=' ',index_col=None,engine='python')The first column is date time in the format 120631135243(YYMMDDhhmmss) .I would like to convert this to a proper date time in the format YY MM DD hh:mm:ss I tried this date1=datetime.datetime.fromtimestamp(data2/1e3)where data2 is data.iloc[1:,0], the first column of the file but resulted in this error Any suggestionsthankyou RE: Python Pandas datetime - ichabod801 - Jan-06-2017 datetime.fromtimestamp takes as a parameter the number of seconds since the epoch. That's not what you have, you have the digits of the various parts of the date/time concatenated together to make an integer. I would break apart the number you have and feed it into the standard datetime constructor, which takes parameters like year, month, day, hour, minutes, and seconds. You could do that either with mod (%) and integer division (//), or you could make the number a string, use slices to get the parts you want, and convert them back into integers. My guess is that the number you have is already a string, and that's why you're getting a conversion error instead of an incorrect date. RE: Python Pandas datetime - snippsat - Jan-06-2017 Quote:The first column is date time in the format 120631135243(YYMMDDhhmmss). Dos raw data look like this? Give a example of input,that is raw. Pandas has a heavy build in Time Series / Date functionality. RE: Python Pandas datetime - nuncio - Jan-08-2017 (Jan-06-2017, 04:48 PM)ichabod801 Wrote: datetime.fromtimestamp takes as a parameter the number of seconds since the epoch. That's not what you have, you have the digits of the various parts of the date/time concatenated together to make an integer. THanks Its working |