Filter data frame using condition
2 answers
You can use the method apply
to return a boolean mask that can be used to select the correct indices. The idea is to define the function that you want to act on each element Series
and apply it (using apply
) the whole series.
def fun(element):
print(element)
if type(element[0])==list:
l=[e[0]=='a' for e in element]
else:
l = [element[0]=='a']
if True in l:
return True
else:
return False
df[df.two.apply(fun)]
0
source to share