简体   繁体   English

如何在pandas数据集中找到最大值

[英]How to find the biggest value in the pandas dataset

I have a dataset that shows the share of every disease from total diseases.我有一个数据集,显示了所有疾病中每种疾病的份额。 I want to find the country name which in that country AIDS is bigger than other diseases.我想找到在那个国家艾滋病比其他疾病更大的国家名称。 数据

试试

df.index[df.AIDS.eq(df.drop('Total',1).max(1))]

Have a look at pandas max function ( https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.max.html )看看熊猫最大函数( https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.max.html

Here you could get the max for each row, as is:在这里,您可以获得每行的最大值,如下所示:

most_frequent_disease = df.drop(columns=['Total', 'Other']).max(axis=1)

Then you can create a condition to check wether AIDS is the most frequent disease, and apply it to your dataframe:然后您可以创建一个条件来检查 AIDS 是否是最常见的疾病,并将其应用于您的数据框:

is_aids_most_frequent_disease = df.loc[:, 'A'].eq(most_frequent_disease)
df[is_aids_most_frequent_disease]

You could get the country name by using the .index at the end of the expression too.您也可以通过在表达式末尾使用.index来获取国家/地区名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM