仅当观察数大于X时,Pandas groupby才会显示

时间:2018-09-04 10:33:41

标签: python pandas pandas-groupby

我有以下代码:我将列预测与列置信度的平均值分组,然后对最高的列10进行排序。我需要对每个组中的观察数进行限制,因为某些组确实是小,因此不应该排在首位。

prediction_difficulty = master.groupby(['prediction'])['confidence']。mean()。reset_index() projection_difficulty.sort_values('confidence',ascending = False)[:10]

1 个答案:

答案 0 :(得分:0)

我认为需要GroupBy.head

prediction_difficulty.sort_values('confidence',ascending=False).groupby('prediction').head(10)
相关问题