英文:
Setting the timezone of a pandas datetime64 column to another column
问题
在给定一个带有datetime64
列和时区列的pandas DataFrame
的情况下,你想知道如何将event_time
列的时区用event_tz
列中指定的时区覆盖。datetime列的tz_localize
和tz_convert
函数似乎只接受单个值,而不是一个Series
。
谢谢你的问题。
英文:
Given a pandas DataFrame
with a datetime64
column and a column representing the timezone:
dates_df = pandas.read_json("""[{"event_time": "2023-04-03T15:03:52", "event_tz": "EDT"}, {"event_time": "2023-04-03T15:03:52", "event_tz": "EDT"}]""")
How can the timezone of the event_time
column be overwritten with the timezone specified in the event_tz
column?
The tz_localize
and tz_convert
functions of the datetime column seem to only accept single values, as opposed to a Series
.
Thank you in advance for your consideration and response.
答案1
得分: 0
pd.to_datetime(dates_df['event_time'].astype(str) + " " + dates_df['event_tz'])
英文:
Based on the suggestion in the comments:
pd.to_datetime(dates_df['event_time'].astype(str) + " " + dates_df['event_tz'])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论