0
我有一个数据帧:Python的大熊猫转换Unix时间戳和时区到日期时间
df = pd.DataFrame({'unix_utc_ts': [1503007204222, 1503007210206, 1503007215121,
1503007220475], 'tz': ['+0000', '+0100', 'CEST', 'EEST']})
我想转换Unix时间戳与时区的日期时间,所以我想是这样的:
df['local_ts'] = pd.to_datetime(df['unix_utc_ts'], unit='ms', tz=df['tz'])
上面的代码不起作用。如果没有tz
说法我得到这个:
tz unix_utc_ts utc_ts
0 +0000 1503007204222 2017-08-17 22:00:04.222
1 +0100 1503007210206 2017-08-17 22:00:10.206
2 CEST 1503007215121 2017-08-17 22:00:15.121
3 EEST 1503007220475 2017-08-17 22:00:20.475
但我当然希望被列入日期时间时区,所以我想这个数据帧:
tz unix_utc_ts utc_ts local_ts
0 +0000 1503007204222 2017-08-17 22:00:04.222 2017-08-17 22:00:04.222
1 +0100 1503007210206 2017-08-17 22:00:10.206 2017-08-17 23:00:10.206
2 CEST 1503007215121 2017-08-17 22:00:15.121 2017-08-18 00:00:15.121
3 EEST 1503007220475 2017-08-17 22:00:20.475 2017-08-18 01:00:20.475
我已经搜索并阅读了大量的问题计算器但没有找到任何工作答案:(
谢谢!