获取DF中最大值的索引名称 [英] Getting index name for the max value in DF

查看:89
本文介绍了获取DF中最大值的索引名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据框:

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中具有最高值的索引名称.会是这样的:

What i want to do is to print out the name of the index with the highest value in the dafaframe. It would be something like this:

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的解决方案也非常好:

@jezrael's solution is also very good:

print(report.index[report['Jaccard'] == report['Jaccard'].max()])

这篇关于获取DF中最大值的索引名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆