Is there a way to convert a pl.Series of type pl.Datetime from one timezone to another?
Question:
I am reading a parquet file with polars
and would like to convert a column called datetime
from type datetime[ms, America/New_York]
to datetime[ns,UTC]
.
I can take the column out and do it in pandas
, use tz_convert
and add the column back to polars dataframe but would be nice if there was a way to do it in polars
🙂
Answers:
As of polars 0.14.14
there is:
pl.col("datetime").dt.with_time_zone
which sets a timezone without modifying the underlying timestamp.
pl.col("datetime").dt.cast_time_zone
which modifies the underlying timestamp by correcting from the current timezone the the given timezone.
EDIT
As of polars 0.16.3
, there is:
pl.col("datetime").dt.convert_time_zone
which sets a timezone without modifying the underlying timestamp.
pl.col("datetime").dt.replace_time_zone
which modifies the underlying timestamp by correcting from the current timezone the the given timezone.
I am reading a parquet file with polars
and would like to convert a column called datetime
from type datetime[ms, America/New_York]
to datetime[ns,UTC]
.
I can take the column out and do it in pandas
, use tz_convert
and add the column back to polars dataframe but would be nice if there was a way to do it in polars
🙂
As of polars 0.14.14
there is:
pl.col("datetime").dt.with_time_zone
which sets a timezone without modifying the underlying timestamp.
pl.col("datetime").dt.cast_time_zone
which modifies the underlying timestamp by correcting from the current timezone the the given timezone.
EDIT
As of polars 0.16.3
, there is:
pl.col("datetime").dt.convert_time_zone
which sets a timezone without modifying the underlying timestamp.
pl.col("datetime").dt.replace_time_zone
which modifies the underlying timestamp by correcting from the current timezone the the given timezone.