我有一个数据集,我使用Groupby并与First一起转换以获得结果。但是它引发了上述错误,请让我知道如何去做。
输入:
Column A Column B
18 1
18 1
20 3
20 1
20 1
24 2
24 1
24 1
18 3
18 1
18 1
18 1
25 1
25 1
25 1
输出:
Column A Column B
18 1
18 1
20 3
20 3
20 3
24 2
24 2
24 2
18 3
18 3
18 3
18 3
25 1
25 1
25 1
现在我正在使用:
df['Column B'] = df.groupby(df['Column A'].ne(df['Column A'].shift()).cumsum())['Column B'].transform('first')
错误:
File "C:\pyhome\lib\site-packages\pandas\core\groupby.py", line 2210, in transform
res = wrapper(group)
File "C:\pyhome\lib\site-packages\pandas\core\groupby.py", line 2203, in <lambda>
wrapper = lambda x: getattr(x, func)(*args, **kwargs)
TypeError: first() takes exactly 2 arguments (1 given)