Extract the value of another index when it is the maximum for one index For example, consider extracting the "elevation at which the signal intensity is maximized" from the DataFrame.
import pandas as pd
df = pd.DataFrame({'elevation': [45.0, 60.0, 75.0, 90.0], \
'intensity': [10.0, 11.1, 12.3, 10.0]})
print(df.loc[df.idxmax()["intensity"]]["elevation"])
The result should be 75.0.
--idxmax (), idxmin () can be used to get the index of each column that is the maximum and minimum. --In this program, the index of DataFrame also works with a string.
df = pd.DataFrame({'elevation': [45.0, 60.0, 75.0, 90.0],\
'intensity': [10.0, 11.1, 12.3, 10.0]},\
index=['a', 'b', 'c', 'd'])
I've been googled the same thing over and over, so I made a note of it. (2020/07/10)
Recommended Posts