I am trying to do as my title says. I have a panda dataframe with datetime and timezone.
I am trying to convert the column startDate to the local naive datetime as follow:
This is the piece of code to do that
df['startDate'] = df['startDate'].apply(lambda x: timezone('UTC').localize(x))
df["startDate"] = df.apply(lambda x: x.startDate.astimezone(timezone(x.timezone)), axis=1)
df["startDate"] = df["startDate"].dt.tz_localize(None)
I get this error message.
Tz-aware datetime.datetime cannot be converted to datetime64 unless utc=True
If I actually precise UTC=True I will get my initial datetime value and that's not what I am trying to achieve
I want to get from this
2020-07-20 20:30:00-07:00
2020-07-21 16:00:00-04:00
2020-07-20 20:30:00-07:00
To this
2020-07-20 20:30:00
2020-07-21 16:00:00
2020-07-20 20:30:00
I am thinking of converting, otherwise, to a string and remove the the 5 last characters and reconverting to a datetime object. However I am looking for a better solution.
Thank you