英文:
Stripping timezone from datetime column
问题
I am trying to strip timezone from the column 'ds':
ds
2023-06-01 00:00:00+00:00
2023-06-01 01:00:00+00:00
2023-06-01 02:00:00+00:00
2023-06-01 03:00:00+00:00
2023-06-01 04:00:00+00:00
Tried the following code:
Usage_df_V2['ds'].astype(str).str[:-6]
But it strips off the hours as well:
2023-06-01 00:00:00
2023-06-01 00:00:00
2023-06-01 00:00:00
2023-06-01 00:00:00
2023-06-01 00:00:00
Also tried the tz_convert but it strips off the time:
Usage_df_V2['ds'].dt.tz_convert(None)
And get the following:
2023-06-01
2023-06-01
2023-06-01
2023-06-01
2023-06-01
Can someone help?
英文:
I am trying to strip timezone from the column 'ds'
ds
2023-06-01 00:00:00+00:00
2023-06-01 01:00:00+00:00
2023-06-01 02:00:00+00:00
2023-06-01 03:00:00+00:00
2023-06-01 04:00:00+00:00
Tried the following code :
Usage_df_V2['ds'].astype(str).str[:-6] but it strips off the hours as well:
2023-06-01 00:00:00
2023-06-01 00:00:00
2023-06-01 00:00:00
2023-06-01 00:00:00
2023-06-01 00:00:00
Also tried the tz_convert but it strips of the time
Usage_df_V2['ds'].dt.tz_convert(None)
& get the following:
2023-06-01
2023-06-01
2023-06-01
2023-06-01
2023-06-01
Can someone help ?
答案1
得分: 1
你几乎说对了。你可以这样去掉时区:
Usage_df_V2['ds'].dt.tz_localize(None)
英文:
You almost got it right. You can drop the timezone like so:
Usage_df_V2['ds'].dt.tz_localize(None)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论