Ask Your Question

How can metadata be linked to a series in Polars?

asked 2022-06-10 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-07-07 08:00:00 +0000

pufferfish gravatar image

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

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.

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


Asked: 2022-06-10 11:00:00 +0000

Seen: 21 times

Last updated: Jul 07 '21