转载至:https://www.cnblogs.com/liulangmao/p/9211537.html

pandas Series 的 argmax 方法和 idxmax 方法用于获取 Series 的最大值的索引值:

举个栗子:

有一个pandas Series,它的索引是国家名,数据是就业率,要找出就业率最高的国家:

import pandas as pd

countries = [
'Afghanistan', 'Albania', 'Algeria', 'Angola',
'Argentina', 'Armenia', 'Australia', 'Austria',
'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh',
'Barbados', 'Belarus', 'Belgium', 'Belize',
'Benin', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina',
] employment_values = [
55.70000076, 51.40000153, 50.5 , 75.69999695,
58.40000153, 40.09999847, 61.5 , 57.09999847,
60.90000153, 66.59999847, 60.40000153, 68.09999847,
66.90000153, 53.40000153, 48.59999847, 56.79999924,
71.59999847, 58.40000153, 70.40000153, 41.20000076,
] # Employment data in 2007 for 20 countries
employment = pd.Series(employment_values, index=countries)

可以这样做:

max_country = employment.idxmax()     

max_country = employment.argxmax()  

# 结果: 'Angola'

如果是一个没有索引值的Series,则返回它的位置索引:

pure_employment = pd.Series(employment_values)
print(pure_employment.argmax())
print(pure_employment.idxmax()) # 结果: 3

最新文章

  1. c# 访问SQL Server 其他会话正在使用事务的上下文
  2. log4net详细配置说明
  3. Mongo命令行中执行CRUD
  4. csu oj 1330 字符识别?
  5. Activity和Service的生命周期(图)
  6. Spring Boot导出jar包发布
  7. 靶形数独 (codevs 1174)题解
  8. HDU 4497 GCD and LCM (数学,质数分解)
  9. 【转】eclipse中egit插件使用
  10. 源码编译安装LAMP环境及配置基于域名访问的多虚拟主机
  11. mvc5 HTML Helper
  12. ios项目不能再用UDID了
  13. Oracle EBS-SQL (BOM-3):检查期间新增Bom数量.sql
  14. Android 自己定义View (二) 进阶
  15. java传值和通过引用传递
  16. Mybatis useGeneratedKeys 填充自增主键值(使用Mysql)的原理分析
  17. JDBC调用MySQL的调用过程CallableStatement
  18. mysql登录密码相关
  19. ios UIButton设置高亮状态下的背景色
  20. TCP/IP, UDP, ICMP, ARP协议族简介--纯图慎点

热门文章

  1. Elasticsearch在Centos 7上的安装与配置
  2. 清空DataGridView
  3. SQL Server中一些不常见的查询
  4. 2018 计蒜之道 初赛 第五场 A 贝壳找房搬家
  5. BZOJ 3622 Luogu P4859 已经没有什么好害怕的了 (容斥原理、DP)
  6. maven jdbc 驱动安装
  7. 前端开发——让算法"动"起来
  8. 关于int,bool,str
  9. spring-boot:run启动时,如何带设置环境参数dev,test.
  10. GC类型以及不同类型GC的搭配 1