In Polars, metadata can be linked to a series using the Series.retain
method. This method allows you to retain metadata from a series and link it to a new series that is created with a derived transformation. For example:
import polars as pl
# Create a series with metadata
s = pl.Series([1, 2, 3], name="my_series", dtype=pl.Int64)
s.set_meta({"foo": "bar"})
# Create a derived series with metadata linked to the original series
s2 = s.retain(name="my_new_series", meta=s.get_meta())
# Print metadata for the new series
print(s2.get_meta())
In the above example, the s.retain
method is used to create a new series called s2
that is a transformation of the original series s
. The metadata from s
is linked to s2
using the meta
parameter in s2.retain
.
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: 2022-06-10 11:00:00 +0000
Seen: 25 times
Last updated: Jul 07 '21