My code is:
def load_data(datafile, categories=None, cat_columns=None):
ohe_categories = 'auto'
if categories and len(categories) > 0:
ohe_categories = categories
ohe = OneHotEncoder(handle_unknown='ignore', categories=ohe_categories)
When categories
is None
, it works fine. But if I pass something, I get an error:
ValueError: The truth value of a Index is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I am calling the function with:
training_x, training_y, categories, cat_columns = loader.load_data(
'data/training.csv')
test_x, test_y = loader.load_data(
'data/test.csv', categories=categories, cat_columns=cat_columns)
How can I check properly?
You are passing a value which doesn't support conversion to a bool
. In this case, you need to explicitly check if the value is not None
:
if categories is not None:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With