英文:
How to convert timestamp with time zone to local time format with pandas?
问题
让我们假设我有一个名为“timestamp”的列,其中包含以下格式的值 -
'2023-02-04 08:08:42+03:00'(当dtype为“Timestamp”时)
转换的预期结果应该是'2023-02-04 05:08:42'
我该如何转换它?
英文:
Let's say I have a column called timestamp with values from the following format -
2023-02-04 08:08:42+03:00
(when the dtype is Timestamp
)
The expected result of the conversion should be 2023-02-04 05:08:42
How can I convert it?
答案1
得分: 1
尝试,
import pandas as pd
s=pd.Series([pd.Timestamp('now',
tz='America/Chicago')])
t=s.dt.tz_convert('utc').dt.tz_localize(None)
print(s,t)
英文:
Try,
import pandas as pd
s=pd.Series([pd.Timestamp('now',
tz='America/Chicago')])
t=s.dt.tz_convert('utc').dt.tz_localize(None)
print(s,t)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论