Ask Your Question
2

How can Python Polars parse date information from an epoch?

asked 2021-12-11 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-08-13 03:00:00 +0000

david gravatar image

Python Polars can parse date information from an epoch by using the from_numpy_datetime function. This function can be used to create a Polars dataframe column containing dates from an epoch in nanoseconds. Here's an example code snippet that demonstrates this:

import polars as pl import numpy as np # Create a numpy array containing epoch timestamps in nanoseconds epoch_array = np.array([1556758800000000000, 1556758860000000000, 1556758920000000000, 1556758980000000000]) # Create a Polars dataframe column from the numpy array date_column = pl.Series.from_numpy_datetime(epoch_array) # Print the date column print(date_column) 

In this example, we first create a numpy array containing epoch timestamps in nanoseconds. We then use the from_numpy_datetime function to create a Polars dataframe column from the numpy array. Finally, we print the date column to verify that it contains the expected date values.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-12-11 11:00:00 +0000

Seen: 8 times

Last updated: Aug 13 '21