convert UTC 2013-01-16 09:04:37.0 into pacific time
Clash Royale CLAN TAG#URR8PPP
convert UTC 2013-01-16 09:04:37.0 into pacific time
There is a data frame "df"
times_utc
2013-01-16 09:04:37.0
I am trying to convert it into pacific time zone
df['times_utc'] = df['times_utc'].dt.tz_convert('US/Pacific')
It gives me this error message:
raise AttributeError("Can only use .dt accessor with datetimelike "
AttributeError: Can only use .dt accessor with datetimelike values
Any thoughts? Thank you!
1 Answer
1
The problem is your column is one of strings. But solving this won't fix the problem. You need to make pandas timezone aware of your column. Do this by localizing the date to UTC first, using tz_localize
. You can then convert it to another timezone as needed, using tz_convert
.
tz_localize
tz_convert
(pd.to_datetime(df.times_utc, errors='coerce')
.dt.tz_localize('UTC')
.dt.tz_convert('US/Pacific'))
0 2013-01-16 01:04:37-08:00
Name: times_utc, dtype: datetime64[ns, US/Pacific]
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.