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?
Pandas DataFrame max() Method The max() method returns a Series with the maximum value of each column. By specifying the column axis ( axis='columns' ), the max() method searches column-wise and returns the maximum value for each row.
To get the position of the maximum value in a range (i.e. a list, table, or row), you can use the MAX function together with the MATCH function. Which returns the number 4, representing the position in this list of the the most expensive property. The MAX function first extracts the maximum value from the range C3:C11.
idxmax() function to find the index label corresponding to the maximum value in the series. Output : As we can see in the output, the Series. idxmax() function has returned the index label of the maximum element in the given series object.
The long answer is the size limit for pandas DataFrames is 100 gigabytes (GB) of memory instead of a set number of cells.
Use argmax()
idxmax()
to get the index of the max value. Then you can use loc
df.loc[df['favcount'].idxmax(), 'sn']
Edit: argmax()
is now deprecated, switching for idxmax()
I think you need idxmax
- get index of max value of favcount
and then select value in column sn
by loc
:
df = pd.DataFrame({'favcount':[1,2,3], 'sn':['a','b','c']})
print (df)
favcount sn
0 1 a
1 2 b
2 3 c
print (df.favcount.idxmax())
2
print (df.loc[df.favcount.idxmax()])
favcount 3
sn c
Name: 2, dtype: object
print (df.loc[df.favcount.idxmax(), 'sn'])
c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With