Reports ambiguous usage of a pandas DataFrame or Series in a boolean context,
such as if, while, or logical expressions.
This typically leads to the runtime error:
ValueError: The truth value of a DataFrame is ambiguous.
In pandas, expressions like df or df == other do not return a single boolean value,
but rather a DataFrame or Series of booleans. Using these in control flow without explicit reduction
(e.g., .any(), .all(), or .empty) is ambiguous and will raise an exception.
δΎ:
if df: # β Raises ValueError: The truth value of a DataFrame is ambiguous
print("DataFrame exists")
if not df.empty: # β
Checks if DataFrame has any rows
print("DataFrame exists")
When the quick-fix is applied, the condition is replaced with an appropriate reducer
like .any(), .all(), or .empty depending on the context.