Reputation: 37
I have a large Pandas dataframe and I want to find out the column and row where the maximum value is (in the entire dataframe). Unfortunately, df.idxmax()
only returns the index for the highest value per row/column, not for the entire dataframe. Is there a way to do this?
Upvotes: 2
Views: 62
Reputation: 44
Use:
# calculates the maximum of each row
# returns the index of the max of max
df.apply(lambda x: max(x.values), axis=1).idxmax()
Upvotes: 1
Reputation: 724
Assuming all data in your dataframe is numeric you can do it easily by converting the dataframe into numpy array:
import numpy as np
df = np.array(df) # Assuming df is your dataframe name
print(np.unravel_index(df.argmax(), df.shape))
Upvotes: 1
Reputation: 23146
Using numpy, you can try:
import numpy as np
>>> np.unravel_index(np.argmax(df.values), df.shape)
Upvotes: 1