I have a python function that calls an API that returns a pandas dataframe. Two of the fields are datetime stamps, which pandas converted from strings.
The problem is that the API reports the datetimes in the local time zone. But the data used in the rest of the application is all UTC, so I need to convert the local timestamps to UTC timestamps.
Here is the code:
my_df = get_external_data(begin_time, end_time)
print(my_df.head())
print(my_df.dtypes)
And the example data:
jobid name user begin end
0 16138 bash noman 2022-12-13 11:33:33 2022-12-13 11:34:21
1 16139 bash noman 2022-12-13 11:34:22 2022-12-13 11:41:47
2 16140 bash noman 2022-12-13 11:41:49 2022-12-13 11:43:33
3 16141 bash noman 2022-12-13 11:49:36 2022-12-13 11:43:33
4 16142 bash noman 2022-12-13 11:57:08 2022-12-13 11:43:33
jobid int64
name string[python]
user string[python]
begin datetime64[ns]
end datetime64[ns]
dtype: object
The program will run in a variety of time zones, so the conversion must be based on the local system's time zone.
How do I convert the timestamps to UTC?