我有以下数据框:
data = {'Algorithm': ['KNN', 'Decision Tree', 'SVM', 'Logistic Regression'],
'Jaccard': [0.75,0.65,0.67,0.70],
'F1-score': [0.69,0.78, 0.75, 0.77],
'LogLoss': ['NA', 'NA', 'NA', 5.23]}
report= pd.DataFrame(data = data)
report = report[['Algorithm', 'Jaccard', 'F1-score', 'LogLoss']]
report.set_index(report['Algorithm'], inplace = True)
report.drop(columns = ['Algorithm'], inplace = True)
我想要做的是打印出dafaframe中具有最高值的索引的名称。它会是这样的:
print(report['Jaccard'][index_name_with_highest_value])
它应该产生:
'KNN'
提前谢谢你:)
最佳答案
尝试np.where
:
print(report.index[np.where(report['Jaccard'].max())[0][0]])
更新尝试np.where
:
print(report['Algorithm'][np.where(report['Jaccard'].max())[0][0]])
或idxmax
:
print(report['Jaccard'].idxmax())
更新:
print(report['Algorithm'][np.where(report['Jaccard']==report['Jaccard'].max())[0][0]])
@jezrael的解决方案也很好:
print(report.index[report['Jaccard'] == report['Jaccard'].max()])
关于python - 获取 DF 中最大值的索引名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52420881/