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.
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
Asked: 2021-12-11 11:00:00 +0000
Seen: 8 times
Last updated: Aug 13 '21
How can popen() be used to direct streaming data to TAR?
In Python, can a string be utilized to retrieve a dataframe that has the same name as the string?
What is the method for merging field value and text into a singular line for display?
What is the method for programmatic access to a time series?