2017-01-17 1 views
3

내가는 loc 기능에서이 조건을 갖고 싶어하지만 && 또는 and 사업자 :팬더 사용하고 LOC 기능의 운영자는

안양 제대로 작동 해달라고 :

business_id ratings review_text 
xyz   2  'very bad' 
xyz   1  'passable' 
xyz   3  'okay' 
abc   2  'so so' 

mycode : 내가 수집하기 위해 노력하고, 그 평가 < 3하고 목록

id = 'xyz' 
mylist = df.loc[df['ratings'] < 3 and df[business_id] ==id,'review_text'].values.tolist() 
,536에 id = xyz있는 모든 review_text

['very bad','passable'] 

이 코드 나던 작업과 나는 오류 얻을 :

내가 가야 내가 어떻게 제대로 여기 and 연산자를 사용합니까

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

를? 필요 요소 현명한 andboolean indexing를보기 때문에

답변

2

당신은, and 논리 연산자에 대한 & 필요

id = 'xyz' 
mylist=df.loc[(df['ratings'] < 3) & (df['business_id'] == id),'review_text'].values.tolist() 
print (mylist) 
['very bad', 'passable'] 
2

가 사용 query

df.query('ratings < 3 & business_id == @id').review_text.tolist() 

["'very bad'", "'passable'"]