问题
From
colA (EST) colB (local tz)
2016-09-19 01:29:13 US/Central
2016-09-19 02:16:04 Etc/GMT+2
2016-09-19 01:57:54 Europe/London
To
colA (EST) colB (local tz) colC (timestamp in local tz)
2016-09-19 01:29:13 US/Central 2016-09-19 02:29:13
2016-09-19 02:16:04 Etc/GMT+2 2016-09-19 08:16:04
2016-09-19 01:57:54 Europe/London 2016-09-19 05:57:54
回答1:
Read the datetime column as timestamp and localize to US/Eastern time and then apply tz_convert
df['colA (EST)'] = pd.to_datetime(df['colA (EST)']).dt.tz_localize('US/Eastern')
df['colC (timestamp in local tz) '] = df.apply(lambda x: x['colA (EST)']\
.tz_convert(x['colB (local tz)']), axis = 1)
colA (EST) colB (local tz) colC (timestamp in local tz)
0 2016-09-19 01:29:13-04:00 US/Central 2016-09-19 00:29:13-05:00
1 2016-09-19 02:16:04-04:00 Etc/GMT+2 2016-09-19 04:16:04-02:00
2 2016-09-19 01:57:54-04:00 Europe/London 2016-09-19 06:57:54+01:00
来源:https://stackoverflow.com/questions/52546068/pandas-how-to-convert-a-timestamp-column-est-to-local-timezone-info-available