Python 基于最大值提取值-数据帧

Python 基于最大值提取值-数据帧,python,pandas,max,Python,Pandas,Max,我正试图根据另一列“total_cases”中的最高值提取一个值“location”,并将其分配给最高的“no_new” 我以前想要从中提取值的数据帧称为no_new_cases 我想从无新病例中找出“总病例数”最多的“位置” 我能够访问最多的“total_案例”,但无法访问以下位置: highest_no_new = no_new_cases['total_cases'].max() 请你帮我把“地点”还给我好吗 提前感谢。使用: 使用: 您可以使用以下方法: 例如: 您可以使用以下方法:

我正试图根据另一列“total_cases”中的最高值提取一个值“location”,并将其分配给最高的“no_new”

我以前想要从中提取值的数据帧称为no_new_cases

我想从无新病例中找出“总病例数”最多的“位置”

我能够访问最多的“total_案例”,但无法访问以下位置:

highest_no_new = no_new_cases['total_cases'].max()
请你帮我把“地点”还给我好吗

提前感谢。

使用:

使用:

您可以使用以下方法:

例如:

您可以使用以下方法:

例如:


谢谢编辑为。。最高不新=不新案例。loc[不新案例['total\u cases'].idxmax,'location']哪个有效:谢谢!编辑为。。最高\u no\u new=无新案例。loc[no\u new\u案例['total\u cases'].idxmax,'location']有效:
df.loc[df['total_cases'].idxmax(), 'location']
df['highest_no_new'] = df.iloc[df.total_cases.argmax()]['location']
>>> d = {'location': [1, 2], 'total_cases': [3, 4]}
>>> df = pd.DataFrame(d)
>>> df
   location  total_cases
0         1            3
1         2            4

>>> df.iloc[df.total_cases.argmax()]['location']
2