I'm working with some data frames that contain Unix epochs in ms, and would like to display the entire timestamp series as a date. Unfortunately, the docs did not help me find a polars native way to do this, and I'm reaching out here. Solutions on how to do this in Python and also in Rust would brighten my mind and day.
With pandas, for example, such things were possible:
pd.to_datetime(pd_df.timestamp, unit="ms")
# or to convert the whole col
pd_df.timestamp = pd.to_datetime(pd_df.timestamp, unit="ms")
I could loop over the whole thing and do something like I'm doing here for a single entry in each row.
datetime.utcfromtimestamp(pl_df["timestamp"][0] / 1000).strftime("%Y-%m-%d")
If I were to do this in Rust, I would then use something like chrono to convert the ts to a date. But I don't think looping over each row is a good solution.
For now, as the best way I have found to help me is to convert pd_df = pl_df.to_pandas()
and do it in pandas.
with_columns
, "unit" is nowtime_unit
– Sunbeam