Stripping timezone from datetime column.

huangapple go评论61阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年6月29日 20:34:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76581116.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定