Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert GPS time to datetime in Python

I have a pandas dataframe with numerous columns, one of which is the time in GPS time, like such:

GPS_time
1635751985
1635751985
1635751986
1635751987
1635751987
……….

How would I go about converting this to datetime or UTC within Python?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the Pandas .to_datetime() method to do this conversion!

>>> df = pd.DataFrame({"dates": [1635751985, 1635751985, 1635751986]})
>>> df
        dates
0  1635751985
1  1635751985
2  1635751986
>>> pd.to_datetime(df["dates"], unit="s")
0   2021-11-01 07:33:05
1   2021-11-01 07:33:05
2   2021-11-01 07:33:06
Name: dates, dtype: datetime64[ns]

Note that this conversion is from your integer values to storing the values as datetime64[ns]
Once converted, you can control how they’re displayed with .dt.strftime() (see How to change the datetime format in Pandas )

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading