Series的idxmax和argmax
2024-09-01 12:16:38
转载至: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
最新文章
- c# 访问SQL Server 其他会话正在使用事务的上下文
- log4net详细配置说明
- Mongo命令行中执行CRUD
- csu oj 1330 字符识别?
- Activity和Service的生命周期(图)
- Spring Boot导出jar包发布
- 靶形数独 (codevs 1174)题解
- HDU 4497 GCD and LCM (数学,质数分解)
- 【转】eclipse中egit插件使用
- 源码编译安装LAMP环境及配置基于域名访问的多虚拟主机
- mvc5 HTML Helper
- ios项目不能再用UDID了
- Oracle EBS-SQL (BOM-3):检查期间新增Bom数量.sql
- Android 自己定义View (二) 进阶
- java传值和通过引用传递
- Mybatis useGeneratedKeys 填充自增主键值(使用Mysql)的原理分析
- JDBC调用MySQL的调用过程CallableStatement
- mysql登录密码相关
- ios UIButton设置高亮状态下的背景色
- TCP/IP, UDP, ICMP, ARP协议族简介--纯图慎点
热门文章
- Elasticsearch在Centos 7上的安装与配置
- 清空DataGridView
- SQL Server中一些不常见的查询
- 2018 计蒜之道 初赛 第五场 A 贝壳找房搬家
- BZOJ 3622 Luogu P4859 已经没有什么好害怕的了 (容斥原理、DP)
- maven jdbc 驱动安装
- 前端开发——让算法";动";起来
- 关于int,bool,str
- spring-boot:run启动时,如何带设置环境参数dev,test.
- GC类型以及不同类型GC的搭配 1