-1
SETUP_T START_T
1690308413 1690309037

I have read in a stdf file into a dataframe with pandas, but the SETUP_T and START_T columns present the time in a way that I am unfamiliar with. Is there any method to convert it to the standard datetime format?

My first reaction was to convert it from seconds to datetime (lol) but I realize it doesn't work that way. I've also tried changing the format of the cell in Excel, but I still don't get the results I need.

Tzane
  • 2,752
  • 1
  • 10
  • 21
zyy
  • 3
  • 2
  • According to the STDF spec, the timestamps are standard Unix epoch timestamps - seconds from midnight January 1, 1970 in local timezone. Which there are several posted answers on how to convert already. – nigh_anxiety Aug 08 '23 at 07:04
  • Does this answer your question? [Converting unix timestamp string to readable date](https://stackoverflow.com/questions/3682748/converting-unix-timestamp-string-to-readable-date) – nigh_anxiety Aug 08 '23 at 07:08

2 Answers2

1

Just using pandas.to_datetime should do the trick:

>>> import pandas as pd
>>> df = pd.DataFrame({"START_T": [1691477659, 1691471659]})
>>> df
      START_T
0  1691477659
1  1691471659
>>> df["START_T_DT"] = pd.to_datetime(df["START_T"], unit="s")
>>> df
      START_T          START_T_DT
0  1691477659 2023-08-08 06:54:19
1  1691471659 2023-08-08 05:14:19
Tzane
  • 2,752
  • 1
  • 10
  • 21
1

It looks like your time values are the seconds passed since 1970-01-01 (Unix epoch). You can use datetime.datetime.fromtimestamp to convert this to a datetime.

Aemyl
  • 1,501
  • 1
  • 19
  • 34