[Python] Use pandas to extract △△ that maximizes ○○

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

[Python] Use pandas to extract △△ that maximizes ○○
[Python] How to use Pandas Series
[Introduction to Python] Let's use pandas
[Introduction to Python] Let's use pandas
[Introduction to Python] Let's use pandas
[Python] Summary of how to use pandas
How to use Pandas 2
python3: How to use bottle (2)
[Python] Convert list to Pandas [Pandas]
String manipulation with python & pandas that I often use
[Python] How to use list 1
How to use Python argparse
How to use Pandas Rolling
Python: How to use pydub
[Python] How to use checkio
[Python] pandas Code that is likely to be reused
I tried to summarize how to use pandas in python
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
Python: How to use async with
How to use Requests (Python Library)
How to use SQLite in Python
[Python] How to use list 3 Added
How to use Mysql in python
How to use OpenPose's Python API
How to use ChemSpider in Python
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
Easy to use Jupyter notebook (Python3.5)
How to use python zip function
[Python] How to use Typetalk API
I want to use a wildcard that I want to shell with Python remove
[Introduction to Python] How to use class in Python?
[Road to intermediate Python] Use ternary operators
How to install and use pandas_datareader [Python]
[Pandas] What is set_option [How to use]
[python] How to use __command__, function explanation
I want to use jar from python
[Introduction to Python] Let's use foreach with Python
[Python] How to use import sys sys.argv
Use pandas to convert grid data to row-holding (?) Data
Easy way to use Wikipedia in Python
How to extract polygon area in Python
[Python] Organizing how to use for statements
Memorandum on how to use gremlin python
[Python2.7] Summary of how to use unittest
[Python] Pandas to fully understand in 10 minutes
python: How to use locals () and globals ()
10 Python errors that are common to beginners
How to use __slots__ in Python class
Install python on xserver to use pip
[Python] Add total rows to Pandas DataFrame
How to use "deque" for Python data
How to use Python zip and enumerate
[Python] Understand how to use recursive functions
Summary of how to use Python list