2017-02-03 3 views
1

내 데이터 프레임에 이미 두 개의 부울 열, lowhigh이 있습니다. 그런 다음 행의 lowhigh 열이 모두 거짓 인 상황을 반영하는 in_range 열을 정의하려고합니다. 여기에 내가 시도 내용은 다음과 같습니다두 개의 다른 부울 열에 의존하는 pandas 부울 열 만들기

df['in_range'] = not (df.low or df.high) 

이 오류가 발생하는 경우를 내가 행별로 행에이 작업을 수행 할 수

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

.

ValueError: can only convert an array of size 1 to a Python scalar

내 코드에 어떤 문제가 및 부울 열을 기존 기반으로 새 부울 열을 생성하는 적절한 방법은 무엇입니까 :이 오류가 발생 .bool()을 추가하는 시도?

답변

0

사용 비트 구문 :

~(df.low | df.high) 

documentation 참조 :

Another common operation is the use of boolean vectors to filter the data. The operators are: | for or, & for and, and ~ for not. These must be grouped by using parentheses.

을 일련의 정확히 NumPy와 ndarray 같이 작동 인덱스 부울 벡터를 사용하여 :