부울 컨텍스트(예: if, while 또는 논리 표현식)에서 pandas DataFrame 또는 Series가 사용된 경우를 경고합니다.
이는 일반적으로 다음 런타임 오류로 이어집니다.
ValueError: The truth value of a DataFrame is ambiguous.
pandas에서 df 또는 df == other과 같은 표현식은 단일 부울 값을 반환하지 않고, 부울의 DataFrame 또는 Series를 반환합니다. 이러한 값을 명시적 축약(예: .any(), .all() 또는 .empty) 없이 제어 흐름에 사용하면 명확하지 않으며 예외가 발생합니다.
예:
if df: # ❌ 'ValueError: The truth value of a DataFrame is ambiguous'라는 오류가 발생합니다
print("DataFrame exists")
if not df.empty: # ✅ DataFrame에 행이 있는지 여부를 확인합니다
print("DataFrame exists")
빠른 수정이 적용되면, 조건은 컨텍스트에 따라 .any(), .all() 또는 .empty와 같은 적절한 축소자로 대체됩니다.