1
list1 = [25,18,65]
customer=pd.DataFrame({
    'id':[1,2,3,4,5,6,7,8,9],
    'name':['Olivia','Aditya','Cory','Isabell','Dominic','Tyler','Samuel','Daniel','Jeremy'],
    'age':[20,25,15,10,30,65,35,18,23],
    'Product_ID':[101,0,106,0,103,104,106,0,107]
})

I need to extract the indices of the rows with ages in list1. I tried

customer[customer['age'] in list1]].index

but this gives me an error

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().```

1 Answers1

0

Don't use in, you should use isin:

customer[customer['age'].isin(list1)]].index

You can't use in in pandas, you only can use pd.Series.isin.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114