bool to data frame pandas

Viewed 44

i have this code in the end i would like to get data frame but i get bool type

df=pd.DataFrame({'dad':[1, 2, 3, 4,5, "T1", "T2"],
      'children':["T1","T1","T2","T2",6,"T3","T3"],
                 "numb":[4,5,6,9,6,7,2]})

children_list=["T1","T2",6]

filter_i=df[df["children"].isin(children_list)]["numb"]>6

print(filter_i)

i want that after the filter ,"filter_i" will be a data frame

1 Answers

I believe you want chain both conditions, here is used & for bitwise AND and then filtering by boolean indexing:

filter_i=df[df["children"].isin(children_list) & (df["numb"]>6)]

Or:

filter_i=df[df["children"].isin(children_list) & df["numb"].gt(6)]
Related