Sorry, I'm starting out in Polars. Is there a way to achieve the same functionality of the shift(n) function where n is a dataframe variable.
When I try:
df = pl.DataFrame({
"a": [1, 2, 3, 4]
, "offset": [1, -1, 1, -1]
})
df.with_columns(shift=pl.col("a").shift(pl.col("offset")))
It gives me the error message:
Traceback (most recent call last):
Cell In[107], line 1
df.with_columns(shift=pl.col("a").shift(pl.col("offset")))
File d:\anaconda3\Lib\site-packages\polars\dataframe\frame.py:8242 in with_columns
return self.lazy().with_columns(*exprs, **named_exprs).collect(_eager=True)
File d:\anaconda3\Lib\site-packages\polars\lazyframe\frame.py:1816 in collect
return wrap_df(ldf.collect(callback))
ComputeError: n must be a single value.
Thank you very much in advance.