I am trying to calculate the difference of lag variable group by id
variable. However,
我在试着用ID变量计算滞后变量组的差值。然而,
when I tried to run the following code:
当我尝试运行以下代码时:
ad.v2.groupby('id').with_columns(
diff = pl.col('Movement_Time_clear') - pl.col('Movement_Time_clear').diff()
)
A warning was popped:
弹出了一个警告:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'LazyGroupBy' object has no attribute 'with_columns'
What was the cause of the warning?
警告的原因是什么?
更多回答
What it says on the tin, LazyGroupBy
doesn't have a with_columns
function. Did you mean agg
?
根据TIN上的内容,LazyGroupBy没有WITH_COLUMNS函数。你是说艾格吗?
If the issue is resolved with agg then you should make that an answer rather than to edit the answer into your question
如果问题是通过AGG解决的,那么您应该将其作为答案,而不是将答案编辑到您的问题中
优秀答案推荐
Thanks for Wayoshi' s reminder, I should use agg
instead of with.columns
...
感谢华友S的提醒,我应该用AGG而不是.Column…
The updated code is as below:
更新后的代码如下:
ad.v2.groupby('id').agg(
diff = pl.col('Movement_Time_clear') -
pl.col('Movement_Time_clear').shift()
).collect()
更多回答
我是一名优秀的程序员,十分优秀!