[英]Getting a python panda data frame's row name as a string
Having found the maximum value in a panda data frame column, I am just trying to get the equivalent row name as a string. 在熊猫数据框列中找到最大值后,我只是想将等效的行名作为字符串获取。
Here's my code: 这是我的代码:
df[df['ColumnName'] == df['ColumnName'].max()].index
Which returns me an answer: 这给了我一个答案:
Index(['RowName'], dtype='object')
How do I just get RowName back? 我该如何找回RowName?
(stretch question - why does .idmax()
fry in the formulation df['Colname'].idmax
? And, yes, I have tried it as .idmax()
and also appended it to df.loc[:,'ColName']
etc.) (拉伸问题-为什么.idmax()
为什么在配方df['Colname'].idmax
?是的,我尝试将其作为.idmax()
并附加到df.loc[:,'ColName']
等)
Just use integer indexing: 只需使用整数索引:
df[df['ColumnName'] == df['ColumnName'].max()].index[0]
Here [0]
extracts the first element. 这里[0]
提取第一个元素。 Note your criterion may yield multiple indices. 请注意,您的条件可能会产生多个索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.