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

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

问题描述

我有一个Pandas DataFrame,其中包含屏幕名称,tweet,收藏夹等.我想找到'favcount'(我已经做过)的最大值,并返回该'tweet'的屏幕名称.

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天全站免登陆