Home > Software design >  Is there a way to convert a pl.Series of type pl.Datetime from one timezone to another?
Is there a way to convert a pl.Series of type pl.Datetime from one timezone to another?

Time:09-27

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 :)

CodePudding user response:

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.

  • Related