I have tried to make a datetime object selected from my dataframe (with a time column: (Time_utc) in Unix time), an aware datetime using to_datetime() method in pandas, but I don't seem to know how. I compared my output (out) with the Unix time converter online tool, and I see that what I indeed have is a naive datetime object.
I tried the following steps:
import pandas as pd
df['date_time'] = pd.to_datetime(df.Time_utc, origin='unix', unit='s')
Printed my results as:
print(df.date_time[0])
out: 2021-08-13 13:27:48
`Result from unixtimeconverter online tool:
Fri Aug 13 2021 13:27:48 GMT+0000
Fri Aug 13 2021 15:27:48 GMT+0200 (Central European Summer Time)
How do I make my out to be an aware datetime?
utc=True?utc=Truein theto_datetime()method and I get, after printingprint(df.date_time[0]):2021-08-13 13:27:48+00:00Also, if I check for the tzinfo(), it now shows it's UTC aware time:print(df.date_time[0].tzinfo):out:UTC. But the offset is still +00:00. How do I get it to +02:00?df['date_time'].dt.tz_convert("Europe/Berlin")