[英]Extract value based on max value - pandas dataframe
I am trying to extract a value (' location ') based on the highest value in another column (' total_cases ') and assign it to highest_no_new
我正在尝试根据另一列(“ total_cases ”)中的最大值提取一个值(“ location ”)并将其分配给
highest_no_new
My previous dataframe where I want to extract the value from is called no_new_cases
我以前想从中提取值的数据
no_new_cases
称为no_new_cases
I want to pick out the ' location ' with the highest number of ' total_cases ' from no_new_cases
我想挑选出与“total_cases”从最多的“位置”
no_new_cases
I am able to access the highest number of ' total_cases ', but not the location:我能够访问最多的“ total_cases ”,但不能访问位置:
highest_no_new = no_new_cases['total_cases'].max()
Please can you help return the 'location'?请你能帮忙返回“位置”吗?
Thanks in advance.提前致谢。
使用idxmax
:
df.loc[df['total_cases'].idxmax(), 'location']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.