I'm trying to isolate and print the maximum value in a pandas dataframe in python.
# Data frame:
df
>> 0 A B C
0 0 0 0 0
A 0 -3 -3 5
B 0 -3 -6 2
C 0 5 0 -3
D 0 5 2 -3
E 0 0 10 5
F 0 -3 5 15
I have managed to isolate the value with the following code:
x = df.max(axis=0)
maxValue = max(x)
maxValue
>> 15
But how can I access this element? Is there a way to iterate through the elements of the data frame such that
for elements in df:
if element == maxValue:
m = element
Or something on those lines? I need to find the largest element, in this case 15, and retrieve its position i.e. (C,F) in this example. I then need to store this and then find the next largest element surrounding the first, along with its position.
# desired output
[(C,F), (B,E), (A,D)]
I hope this makes sense! Any advice on how I could implement this would be much appreciated! :)