pandas条件组合筛选和按范围筛选的示例代码
作者:咿咿呀呀呀 时间:2023-06-13 07:15:37
1、从记录中选出所有fault_code列的值在fault_list= [487, 479, 500, 505]这个范围内的记录
record2=record[record['FAULT_CODE'].isin(fault_list)]
要用.isin 而不能用in,用 in以后选出来的值都是True 和False,然后报错:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any()
2、选出所有WTGS_CODE=20004013的记录
set=20004013
record= record[record['WTGS_CODE'] == set]
3、其次,从记录中选出所有满足set条件且fault_code列的值在fault_list= [487, 479, 500, 505]这个范围内的记录
record_this_month=record[(record['WTGS_CODE']==set)&(record['FAULT_CODE'].isin(fault_list))]
(1)多个条件筛选的时候每个条件都必须加括号。
(2)判断值是否在某一个范围内进行筛选的时候需要使用DataFrame.isin()的isin()函数,而不能使用in。
来源:https://blog.csdn.net/orangefly0214/article/details/82712117
标签:pandas,筛选
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python常见的格式化输出小结
2022-12-29 20:23:31
MySql创建分区的方法实例
2024-01-23 22:17:40
![](https://img.aspxhome.com/file/2023/4/126274_0s.png)
浅析python标准库中的glob
2023-08-04 02:39:10
MySQL 8.0 之不可见列的基本操作
2024-01-18 17:32:41
快速创建python 虚拟环境
2023-10-04 08:58:31
![](https://img.aspxhome.com/file/2023/9/95379_0s.png)
python基础知识小结之集合
2021-07-14 23:34:54
Python实现的knn算法示例
2022-09-21 14:35:09
![](https://img.aspxhome.com/file/2023/0/114790_0s.png)
怎么让按钮更容易被点击
2007-08-22 09:07:00
![](https://img.aspxhome.com/file/UploadPic/20078/22/200782291027419s.gif)
Python编程实现简单的微博自动点赞
2021-05-14 06:43:12
![](https://img.aspxhome.com/file/2023/4/128204_0s.jpg)
Python 文件与文件对象及文件打开关闭
2021-06-16 16:08:44
python实现超级玛丽游戏
2023-10-02 20:19:28
![](https://img.aspxhome.com/file/2023/9/99299_0s.gif)
Python Pandas高级教程之时间处理
2021-08-12 14:04:49
获取SQL Server表字段的各种属性实例代码
2024-01-26 13:13:11
Python xlwt设置excel单元格字体及格式
2023-03-10 06:04:39
![](https://img.aspxhome.com/file/2023/1/70021_0s.png)
python操作redis方法总结
2021-12-07 05:51:22
python机器学习基础线性回归与岭回归算法详解
2021-03-09 07:29:43
![](https://img.aspxhome.com/file/2023/6/131696_0s.png)
Django 返回json数据的实现示例
2021-03-06 21:33:17
![](https://img.aspxhome.com/file/2023/0/92350_0s.png)
Pytest执行unittest TestSuite(测试套件)的实现方法
2023-12-23 06:05:14
Python编写检测数据库SA用户的方法
2024-01-16 07:11:57
解决python selenium3启动不了firefox的问题
2022-12-02 11:36:34
![](https://img.aspxhome.com/file/2023/2/105882_0s.jpg)