Pandas 最大值指数 [英] Pandas max value index

查看:38
本文介绍了Pandas 最大值指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个混合了屏幕名称、推文、收藏夹等的 Pandas DataFrame.我想找到favcount"的最大值(我已经完成了)并返回该推文"的屏幕名称

I have a Pandas DataFrame with a mix of screen names, tweets, fav's etc. I want find the max value of 'favcount' (which i have already done) and also return the screen name of that 'tweet'

df = pd.DataFrame()
df['timestamp'] = timestamp
df['sn'] = sn
df['text'] = text
df['favcount'] = fav_count


print df
print '------'
print df['favcount'].max()

我似乎无法找到任何关于此的信息,任何人都可以帮助指导我朝着正确的方向前进吗?

I cant seem to find anything on this, can anyone help guide me in the right direction?

推荐答案

使用 argmax() idxmax() 获取索引最大值.然后你可以使用 loc

Use argmax() idxmax() to get the index of the max value. Then you can use loc

df.loc[df['favcount'].idxmax(), 'sn']

argmax() 现在已弃用,切换为 idxmax()

这篇关于Pandas 最大值指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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