Python 删除列上带有条件的整行
以下是张贴在此处的问题和解决方案: 我想问一下如何删除列值上具有组合运算符条件的行。简而言之,我喜欢删除第三列值不在7到15之间的所有行Python 删除列上带有条件的整行,python,numpy,Python,Numpy,以下是张贴在此处的问题和解决方案: 我想问一下如何删除列值上具有组合运算符条件的行。简而言之,我喜欢删除第三列值不在7到15之间的所有行 print (data[:,2]) to_remove = data[:,2] < 7 and data[:,2] >= 15 上面的行是不允许的,它会抛出一个值错误 ValueError:包含多个元素的数组的真值不明确。使用a.any或a.all 尝试: 我想你需要这样的东西: result = [] for row in arr
print (data[:,2])
to_remove = data[:,2] < 7 and data[:,2] >= 15
上面的行是不允许的,它会抛出一个值错误
ValueError:包含多个元素的数组的真值不明确。使用a.any或a.all
尝试:
我想你需要这样的东西:
result = []
for row in arr: # loop over the rows
if row[2] > 7 and row[2] < 15: # this is the condition you need
result.append(row) # store the rows which third column is between 7 and 15 in a new array
print(result)
删除=data[:,2]<7 | data[:,2]>=15谢谢。现在来谈谈我真正的问题。我的列值为floats=2.88168034e+01。因此,to_remove=data[:,2]<20.|数据[:,2]>19。应该从数组中删除所有条目,但我看到的警告是fetchRuns。py:21:FutureWarning:在将来,insert将把布尔数组和类似数组视为布尔索引,而不是将其强制转换为整数new\u data=np.deletedata,要删除,axis=0
result = []
for row in arr: # loop over the rows
if row[2] > 7 and row[2] < 15: # this is the condition you need
result.append(row) # store the rows which third column is between 7 and 15 in a new array
print(result)