gpt4 book ai didi

DataFrame groupby().apply() 函数似乎被调用了两次

转载 作者:行者123 更新时间:2023-12-05 05:19:48 25 4
gpt4 key购买 nike

这是一个简单的 DataFrame:

import numpy as np
dd=pd.DataFrame(np.arange(35).reshape(7,5), columns=list('xyzwv'))
dd['w']=list('AABBBCC')

,即:

enter image description here

现在我尝试下面的代码

def func(x):
print(x)
return x

dd.groupby('w').apply(func)

然后打印出来:

enter image description here

我认为出了问题,因为 enter image description here正在打印两次。

看起来好像 func() 被同一组调用了两次。我做错了什么?

最佳答案

apply 两次调用第一组来确定它是否可以做一些优化,见 http://pandas.pydata.org/pandas-docs/stable/groupby.html#flexible-apply

关于DataFrame groupby().apply() 函数似乎被调用了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45530875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com