我有以下数据集:

df['Coefficient'] = [0.1,0.2,0.1,0.5,0.2,0.3,0.2,0.6,0.9,0.8,0.5,0.3,0.5,0.8,0.4,0.1,0.2,0.5,0.9,0.7,0.2,0.5,0.5,0.2,0.8,0.3,0.6,0.5,0.2,0.2,0.4,0.1,0.3,0.9,0.8,0.2,0.5,0.6,0.5]


如何使用python查找输入最多的三个系数值?

最佳答案

您可以将value_counts用于选择第一个3索引值,因为value_counts对输出进行排序:

print (df['Coefficient'].value_counts())
0.2    9
0.5    9
0.3    4
0.1    4
0.8    4
0.6    3
0.9    3
0.4    2
0.7    1
Name: Coefficient, dtype: int64

print (df['Coefficient'].value_counts().index[:3])
Float64Index([0.2, 0.5, 0.3], dtype='float64')

关于python - 如何在列中找到三个输入最多的值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43536026/

10-08 21:02