作者:mobiledu2502860217 | 来源:互联网 | 2024-10-18 13:20
1、从记录中选出所有fault_code列的值在fault_list[487,479,500,505]这个范围内的记录record2record[record[FAULT_CODE
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。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。