问题描述
我只需要从系列(“荧光”)中打印高于某个数值阈值的元素。
如何将一个元素与同一系列中的另一个元素进行比较,如果不满足条件,只需在该系列中继续?
ClassCastException
我想要的是以下内容:
提前致谢
解决方法
filter() 正是您所需要的。
# Filter will filter an iterator if the function returns True
fluorescence = [94,35,12,104]
result = list(filter(lambda x: x > 43,fluorescence))
print(result)
# [94,104]
,
iteritems
返回 (key,value) 的元组。您无法将整个元组与标量进行比较。
if i[1] > 43:
应该可以解决您的问题。请参阅其他答案以获得获得结果的更好方法。
,Pandas tolist() 会将系列转换为易于迭代的列表。
#an empty list to store the values
new=[]
for i in fluorescence.tolist():
if i > 43
new.append(i)
print(new)
#print statement not in the loop