mGarsteck mGarsteck - 5 months ago 58
Python Question

Pandas max value index

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?


use .argmax() to get the index of the max value. then you can use loc

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