<分区>
import time
np.random.seed(0)
df = pd.DataFrame({'gr': np.random.choice(7000, 500000),
'col': np.random.choice(1000, 500000)})
groups = df.groupby('gr')
t1 = time.time()
idx = groups.col.idxmax()
print(round(time.time() - t1,1))
0.7
有没有办法比使用 idxmax() 更快地获得这些指数?
注意,我对idx.values
感兴趣,我不介意丢失idx
的idx.index()
系列